Where can I find a formal specification (in EBNF, or some other standard notation -- the source code for the "read" function doesn't count!) for the Emacs Lisp grammar?
I'd even be happy with a .y file; unfortunately, emacs's own parser does not use yacc.
I think that it is the same as for any lisp language, isn't it? Here is one describing Lisp from the Lisp page in Wikipedia:
expression -> atom | list
atom -> number | name | string | operator
list -> '(' expression* ')'
Related
I'm writing bnf notation with Jison and getting an reduce/reduce conflict:
Conflict at state: 26, token: SIMPLE_ASSIGN
reduce by rule: PrimaryExpression -> Identifier
reduce by rule: LeftHandSideExpression -> Identifier
My State 26 looks like this:
item set 24
AssignmentExpression -> LeftHandSideExpression .AssignmentOperator AssignmentExpression
AssignmentOperator -> .SIMPLE_ASSIGN
AssignmentOperator -> .COMPLEX_ASSIGN
transitions -> {"AssignmentOperator":61,"SIMPLE_ASSIGN":62,"COMPLEX_ASSIGN":63}
item set 25
LogicalORExpression -> LogicalANDExpression .
LogicalANDExpression -> LogicalANDExpression .LOGICAL_AND EqualityExpression
transitions -> {"LOGICAL_AND":64}
item set 26
LeftHandSideExpression -> Identifier .
PrimaryExpression -> Identifier .
transitions -> {}
item set 27
LogicalANDExpression -> EqualityExpression .
EqualityExpression -> EqualityExpression .EQUALITY_OPERATOR RelationalExpression
transitions -> {"EQUALITY_OPERATOR":65}
How would I figure out the problem here and fix it?
I am using Jison, and I am running:
jison -p lalr -t grammer/noa.bnf -t > log
Interestingly I am also using syntax-cli which doesn't produce a reduce/reduce conflict, but still has trouble parsing.
What that is telling you is that there is some grammatical production in which the non-terminal PrimaryExpression (or some non-terminal whose expansion ends with PrimaryExpression) can be followed by a SIMPLE_ASSIGN (or some non-terminal whose expansion starts with SIMPLE_ASSIGN, although that seems unlikely). In that context, Identifier (whose expansion isn't shown) is ambiguous, because both PrimaryExpression and LeftHandSideExpression can expand to Identifier.
It's hard to guess what context that might be, but it should be reasonably simple to track down: just look at every non-terminal which can precede SIMPLE_ASSIGN until you find one which can end with PrimaryExpression. (Not all such productions are errors, though. It's really highly dependent on the grammar.)
As the title suggest, my prolog code is throwing a syntax error. Im not sure what Im doing wrong. Im using Swi for my IDE and I tried playing with it to fix the problem, but to no avail.
heres my simple prolog code with error
?-
| male(bob)
| male(jeff)
|
| female(jane)
| female(erica)
|
| father(bob,jane)
| mother(erica, jane)
|
| ?-mother(erica,X).
ERROR: Syntax error: Operator expected
ERROR: male(bob)
ERROR: ** here **
ERROR:
male(jeff)
female(jane)
female(erica)
father(bob,jane)
mother(erica, jane)
?-mother(erica,X) .
There are two phases of Prolog development: Writing the program and interacting with it in the Prolog shell. These two phases are separate. You don't write your program in the shell, at least not directly.
Save your facts in a file called family.pl (with a dot . at the end of each fact!), then start the Prolog shell. In the shell, you can load the program using
?- consult(family).
or
?- consult('family.pl').
Note that in the first case you leave off the .pl extension, but in the second case, if you do use the extension, you should use single quotes (') around the file name.
Now you can run your query:
?- mother(erica, X).
X = jane.
There are some other ways to load files, such as putting the file name between square brackets [] instead of using consult, or (for many Prolog systems) simply adding the file name on the command line.
Statements in prolog end with a dot:
male(jeff).
female(jane).
female(erica).
father(bob,jane).
mother(erica, jane).
For reference, I'm using this version of the shell.
I'm looking to evaluate a math expression containing exponents. How can I do so? expr isn't available in es-shell, and neither do the double parends work (as they do in other shells).
The expression I want to evaluate is 2^69 (2 to the 69th power). I've tried with both ** and ^ for exponentiation.
I'm looking for a solution that doesn't use an external calculator, hopefully pure es-shell code.
Most Unix shells delegate math to some other command. bc is probably available on your machine, since it's a POSIX utility. Invoke it from es like this:
; echo `{echo '2 ^ 69' | bc}
590295810358705651712
I am trying to write an ANTLR4 grammar to parse actionscript3. I've decided to start with something fairly coarse grained:
grammar actionscriptGrammar;
OBRACE:'{';
CBRACE:'}';
STRING_DELIM:'"';
BLOCK_COMMENT : '/*' .*? '*/' -> skip;
EOL_COMMENT : '//' .*? '/n' -> skip;
WS: [ \n\t\r]+ -> skip;
TEXT: ~[{} \n\t\r"]+;
thing
: TEXT
| string_literal
| OBRACE thing+? CBRACE;
string_literal : STRING_DELIM .+? STRING_DELIM;
start_rule
: thing+?;
Basically, I want a tree of things grouped by their lexical scope. I want comments to be ignored, and string literals be their own things so that any braces they may include do not affect lexical scope. The string_literal rule works fine (such as it is) but the two comment rules don't appear to have any effect. (i.e. comments aren't being ignored).
What am I missing?
This is from a simplified Java grammar I wrote in ANTLR v4.
WS
: [ \t\r\n]+ -> channel(HIDDEN)
;
COMMENT
: '/*' .*? '*/' -> skip
;
LINE_COMMENT
: '//' ~[\r\n]* -> skip
;
May be this could help you out.
Also, try rearranging your code. Write the Parser Rules first and Lexer Rules last. Follow a Top-Down approach. I find it much more helpful in debugging. It will also look nice when you create an HTML export of your grammar from ANTLR 4 Eclipse Plugin.
Good Luck!
The answer is that your TEXT rule is consuming your comments. Rather than using a negated set, use something like:
TEXT: [a-zA-Z0-9_][/a-zA-Z0-9.;()\[\]_-]+ ;
That way, your comments cannot be matched by TEXT.
I am reading Software foundations book and I came across a command that declares parameters
as implicit:
Arguments nil {X}.
where, for example:
Inductive list (X:Type) : Type :=
| nil : list X
| cons : X -> list X -> list X.
However, whenever I try to execute such commands I get the following message:
Error: No focused proof (No proof-editing in progress).
The same message appears even if I try to compile scripts that come with the book. What could be the problem?
I am using Coq version 8.3pl4 and CoqIDE editor.
I just tried it on my (somewhat old) Coq 8.4 and I don't have any problem with the implicit declaration.
However if I write Argument instead of Arguments (notice the lack of "s"), I get
Error: Unknown command of the non proof-editing mode.
Did you correctly spelled it ?
EDIT: sorry, I miss-read your version. It seems that the Arguments command has been added post 8.4 (it does not appear here but appears here. I advise you update your Coq version if possible, or restrict to using 8.3 Implicit related commands (wild guess: Implicit Arguments foo.)