Skip to content
Snippets Groups Projects
Unverified Commit 7dea620a authored by Recolic Keghart's avatar Recolic Keghart
Browse files

finish p4

parent 0bbdf2ed
No related branches found
No related tags found
No related merge requests found
/* Template for HW1, problem #4a
* The makefile has instructions for turning these templates into
* executables. Just use the command 'make' in this directory.
* To test your solution, put the inputs to be tested, one to a
* line, in some file INPUTFILE, and enter the command
*
* ./P4a INPUTFILE
*
* or
*
* ./P4a < INPUTFILE
*
* Or, just type
*
* ./P4a
*
* and enter inputs, one per line, by hand (on Unix, use ^D to end this input,
* or ^C^D in an Emacs shell).
*/
%{
extern int yylex();
extern int yyerror(const char*);
%}
%glr-parser
%start ANSWER
%%
/* Insert a regular grammar that defines the nonterminal symbol
* ANSWER to be a language equivalent to the corresponding regular
* expression in problem 2. */
/* REPLACE WITH YOUR SOLUTION */
ZEROONE : '0'
| '1' ;
ANY_ZEROONE : ZEROONE ANY_ZEROONE
| %empty ;
ANSWER : '0' ANY_ZEROONE '0' ;
/* End of grammar */
%%
#include <stdlib.h>
#include <stdio.h>
/** Returns terminal symbols '0' or '1', skipping any other
* character. */
int
yylex()
{
while (1) {
int c = getchar();
if (c == EOF)
return 0;
else if (c == '0' || c == '1')
return c;
}
}
int
yyerror(const char* msg) {
fprintf(stderr, "The input is not in the language.\n");
exit(0);
}
int
main(int argc, char* argv[])
{
if (argc > 1) {
if (freopen(argv[1], "r", stdin) == NULL) {
fprintf(stderr, "Could not read file %s\n", argv[1]);
exit(1);
}
}
yyparse();
fprintf(stderr, "The input is in the language.\n");
exit(0);
}
/* Template for HW1, problem #4b
* The makefile has instructions for turning these templates into
* executables. Just use the command 'make' in this directory.
* To test your solution, put the inputs to be tested, one to a
* line, in some file INPUTFILE, and enter the command
*
* ./P4b INPUTFILE
*
* or
*
* ./P4b < INPUTFILE
*
* Or, just type
*
* ./P4b
*
* and enter inputs, one per line, by hand (on Unix, use ^D to end this input,
* or ^C^D in an Emacs shell).
*/
%{
extern int yylex();
extern int yyerror(const char*);
%}
%glr-parser
%start ANSWER
%%
/* Insert a regular grammar that defines the nonterminal symbol
* ANSWER to be a language equivalent to the corresponding regular
* expression in problem 2. */
/* REPLACE WITH YOUR SOLUTION */
ANYONE : '1' ANYONE
| %empty ;
PACK1 : '0' ANYONE ;
ANY_PACK1 : PACK1 ANY_PACK1
| %empty ;
ANSWER : ANY_PACK1 ;
/* End of grammar */
%%
#include <stdlib.h>
#include <stdio.h>
/** Returns terminal symbols '0' or '1', skipping any other
* character. */
int
yylex()
{
while (1) {
int c = getchar();
if (c == EOF)
return 0;
else if (c == '0' || c == '1')
return c;
}
}
int
yyerror(const char* msg) {
fprintf(stderr, "The input is not in the language.\n");
exit(0);
}
int
main(int argc, char* argv[])
{
if (argc > 1) {
if (freopen(argv[1], "r", stdin) == NULL) {
fprintf(stderr, "Could not read file %s\n", argv[1]);
exit(1);
}
}
yyparse();
fprintf(stderr, "The input is in the language.\n");
exit(0);
}
/* Template for HW1, problem #4c
* The makefile has instructions for turning these templates into
* executables. Just use the command 'make' in this directory.
* To test your solution, put the inputs to be tested, one to a
* line, in some file INPUTFILE, and enter the command
*
* ./P4c INPUTFILE
*
* or
*
* ./P4c < INPUTFILE
*
* Or, just type
*
* ./P4c
*
* and enter inputs, one per line, by hand (on Unix, use ^D to end this input,
* or ^C^D in an Emacs shell).
*/
%{
extern int yylex();
extern int yyerror(const char*);
%}
%glr-parser
%start ANSWER
%%
/* Insert a regular grammar that defines the nonterminal symbol
* ANSWER to be a language equivalent to the corresponding regular
* expression in problem 2. */
/* REPLACE WITH YOUR SOLUTION */
ANY : '0'
| '1' ;
ANY_STAR : ANY ANY_STAR
| %empty ;
ANSWER : ANY_STAR '0' ANY ANY;
/* End of grammar */
%%
#include <stdlib.h>
#include <stdio.h>
/** Returns terminal symbols '0' or '1', skipping any other
* character. */
int
yylex()
{
while (1) {
int c = getchar();
if (c == EOF)
return 0;
else if (c == '0' || c == '1')
return c;
}
}
int
yyerror(const char* msg) {
fprintf(stderr, "The input is not in the language.\n");
exit(0);
}
int
main(int argc, char* argv[])
{
if (argc > 1) {
if (freopen(argv[1], "r", stdin) == NULL) {
fprintf(stderr, "Could not read file %s\n", argv[1]);
exit(1);
}
}
yyparse();
fprintf(stderr, "The input is in the language.\n");
exit(0);
}
/* Template for HW1, problem #4d
* The makefile has instructions for turning these templates into
* executables. Just use the command 'make' in this directory.
* To test your solution, put the inputs to be tested, one to a
* line, in some file INPUTFILE, and enter the command
*
* ./P4d INPUTFILE
*
* or
*
* ./P4d < INPUTFILE
*
* Or, just type
*
* ./P4d
*
* and enter inputs, one per line, by hand (on Unix, use ^D to end this input,
* or ^C^D in an Emacs shell).
*/
%{
extern int yylex();
extern int yyerror(const char*);
%}
%glr-parser
%start ANSWER
%%
/* Insert a regular grammar that defines the nonterminal symbol
* ANSWER to be a language equivalent to the corresponding regular
* expression in problem 2. */
/* REPLACE WITH YOUR SOLUTION */
ANY_ZERO : '0' ANY_ZERO
| %empty ;
ANSWER : ANY_ZERO '1' ANY_ZERO '1' ANY_ZERO '1' ANY_ZERO;
/* End of grammar */
%%
#include <stdlib.h>
#include <stdio.h>
/** Returns terminal symbols '0' or '1', skipping any other
* character. */
int
yylex()
{
while (1) {
int c = getchar();
if (c == EOF)
return 0;
else if (c == '0' || c == '1')
return c;
}
}
int
yyerror(const char* msg) {
fprintf(stderr, "The input is not in the language.\n");
exit(0);
}
int
main(int argc, char* argv[])
{
if (argc > 1) {
if (freopen(argv[1], "r", stdin) == NULL) {
fprintf(stderr, "Could not read file %s\n", argv[1]);
exit(1);
}
}
yyparse();
fprintf(stderr, "The input is in the language.\n");
exit(0);
}
/* Template for HW1, problem #4e
* The makefile has instructions for turning these templates into
* executables. Just use the command 'make' in this directory.
* To test your solution, put the inputs to be tested, one to a
* line, in some file INPUTFILE, and enter the command
*
* ./P4e INPUTFILE
*
* or
*
* ./P4e < INPUTFILE
*
* Or, just type
*
* ./P4e
*
* and enter inputs, one per line, by hand (on Unix, use ^D to end this input,
* or ^C^D in an Emacs shell).
*/
%{
extern int yylex();
extern int yyerror(const char*);
%}
%glr-parser
%start ANSWER
%%
/* Insert a regular grammar that defines the nonterminal symbol
* ANSWER to be a language equivalent to the corresponding regular
* expression in problem 2. */
/* REPLACE WITH YOUR SOLUTION */
OOII : '0' '0'
| '1' '1' ;
OIIO : '0' '1'
| '1' '0' ;
OOII_STAR : OOII OOII_STAR
| %empty ;
PACK2 : OIIO OOII_STAR OIIO OOII_STAR ;
PACK2_STAR : PACK2 PACK2_STAR
| %empty ;
ANSWER : OOII_STAR PACK2_STAR;
/* End of grammar */
%%
#include <stdlib.h>
#include <stdio.h>
/** Returns terminal symbols '0' or '1', skipping any other
* character. */
int
yylex()
{
while (1) {
int c = getchar();
if (c == EOF)
return 0;
else if (c == '0' || c == '1')
return c;
}
}
int
yyerror(const char* msg) {
fprintf(stderr, "The input is not in the language.\n");
exit(0);
}
int
main(int argc, char* argv[])
{
if (argc > 1) {
if (freopen(argv[1], "r", stdin) == NULL) {
fprintf(stderr, "Could not read file %s\n", argv[1]);
exit(1);
}
}
yyparse();
fprintf(stderr, "The input is in the language.\n");
exit(0);
}
submit @ 979faff2
Subproject commit 0e37d1d0fafb230324808d2a1447b4b9b52aa8ff Subproject commit 979faff2d7523d8a0a02fb8293a4d9272b7f0232
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment