Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: uberj/cs480_milestones
base: 06cf0d5f17
...
head fork: uberj/cs480_milestones
compare: c5cd77f919
  • 3 commits
  • 4 files changed
  • 0 commit comments
  • 2 contributors
View
25 factored_grammar.txt
@@ -0,0 +1,25 @@
+F -> T F
+T -> ( S )
+S -> ( ) |
+
+ -> atom | <---+--- amb. [1]
+ -> atom S | <---+
+
+ -> ( S ) | <-- amb. [2]
+ -> () S |
+ -> ( S ) S <-- amb. [3]
+
+Fixes
+-----
+S' -> S | e <-- This fixes the above problem
+
+[1]
+S -> atom S'
+
+[2]
+S -> ( S' )
+
+[3]
+S -> ( S' ) S'
+S -> atom S'
+
View
19 parser.rb
@@ -12,7 +12,7 @@ def expect(enum, tag)
raise SyntaxError
end
rescue StopIteration
- raise SyntaxError
+ raise SyntaxError
end
end
@@ -22,14 +22,18 @@ def parser
tree = []
tokens = tokenize(input).to_enum
- begin
- loop do
- tree << expect(tokens, :openparen)
+ loop do
+ # If we are at the end of the file, this will raise a StopIteration, and stop the loop. Otherwise, expect will throw an error.
+ t = tokens.peek
+ if t.nil?
+ break
+ elsif t.tag == :openparen
+ tree << tokens.next
tree << expr(tokens)
tree << expect(tokens, :closeparen)
+ else
+ raise SyntaxError
end
- rescue SyntaxError
- puts "Found SyntaxError"
end
puts "+++ Tree Format +++"
@@ -46,8 +50,7 @@ def expr(tokens)
if t.tag == :closeparen
break
elsif t.tag == :openparen
- tokens.next
- tree << t
+ tree << tokens.next
tree << expr(tokens)
tree << expect(tokens, :closeparen)
else
View
4 test_grammars/good_expr/test7.gm
@@ -1 +1,5 @@
+<<<<<<< HEAD
+(2)
+=======
(+ 1 1)
+>>>>>>> 06cf0d5f17557663a96e1034a38910308d322e72
View
2  test_parser.sh
@@ -65,6 +65,8 @@ do
test_bad
;;
*)
+ test_good
+ test_bad
;;
esac
done

No commit comments for this range

Something went wrong with that request. Please try again.