Commit 6ac0a84f authored by Pascal J. Bourguignon's avatar Pascal J. Bourguignon

Corrected parse tree synthesis for expressions and declarations.

parent 6d9a8263
This diff is collapsed.
This diff is collapsed.
(in-package "COM.INFORMATIMAGO.LANGUAGES.C11.PARSER")
;; (in-package "COM.INFORMATIMAGO.LANGUAGES.C11.PARSER")
(defpackage "TEST"
(:use "COMMON-LISP"
"COM.INFORMATIMAGO.RDP"))
(in-package "TEST")
(defgrammar simple-ex
:scanner t
:terminals ((identifier "[A-Za-z][A-Za-z0-9]*")
(integer "[0-9]+"))
:start expression
:rules ((--> expression
(alt
(seq "+" integer)
(seq "-" integer)
(seq "*" integer)
(seq "/" integer)))))
(defgrammar ex
......@@ -50,7 +67,7 @@
(--> rep-with-action
"rep-with-action" (rep identifier integer) ; :action `(,identifier ,integer)
:action `(rep-no-action ,@(reduce 'append $2)))
:action `(rep-with-action ,@(reduce 'append $2)))
(--> opt-no-action
......@@ -67,6 +84,9 @@
"alt-with-action" (alt (seq "with" :action 'with) (seq "without" :action 'without)) identifier)))
#-(and) (progn
(parse-ex "impl-seq-no-action hello 42")
(expression (impl-seq-no-action (|impl-seq-no-action| "impl-seq-no-action" 19) (identifier "hello" 25) (integer "42" 28)))
......@@ -95,9 +115,10 @@
(list (parse-ex "rep-with-action")
(parse-ex "rep-with-action hello 42")
(parse-ex "rep-with-action hello 42 world 33"))
((expression (rep-no-action))
(expression (rep-no-action (identifier "hello" 22) (integer "42" 25)))
(expression (rep-no-action (identifier "hello" 22) (integer "42" 25) (identifier "world" 31) (integer "33" 34))))
((expression (rep-with-action))
(expression (rep-with-action (identifier "hello" 22) (integer "42" 25)))
(expression (rep-with-action (identifier "hello" 22) (integer "42" 25) (identifier "world" 31) (integer "33" 34))))
(parse-ex "opt-no-action")
(expression (opt-no-action (|opt-no-action| "opt-no-action" 14) nil))
......
......@@ -22,7 +22,7 @@ int f(int argument)
ivar=42;
svar="hello";
ivar=(1+2);
svar=("Hello" " " "World");
svar=("Hello World");
// TODO: generic_selection
int unary_expressions;
......@@ -156,9 +156,9 @@ int f(int argument)
int sequence_expressions;
ivar=a,b,c;
ivar=(a++),
f(b),
a*x*x+b*x+c,
ivar=((a++),
f(b),
a*x*x+b*x+c),
(a*x+b)*x+c;
int z=1+2*3/4;
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment