├── .gitignore ├── .gitpod.Dockerfile ├── .gitpod.yml ├── .idea ├── codeStyles │ └── codeStyleConfig.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml ├── uiDesigner.xml ├── vcs.xml └── workspace.xml ├── .vscode └── launch.json ├── LICENSE ├── README.md ├── While.iml ├── _config.yml ├── compilar.bat ├── compilar.sh ├── doc ├── README.md └── images │ ├── Espaco.png │ ├── ID.png │ ├── INT.png │ ├── Texto.png │ ├── bool.png │ ├── comando.png │ ├── expressao.png │ ├── programa.png │ └── seqComando.png ├── lib ├── antlr-4.13.1-complete.jar └── antlr-runtime-4.13.1.jar ├── olamundo.while ├── src └── plp │ └── enquanto │ ├── Linguagem.java │ ├── Principal.java │ ├── Propriedades.java │ ├── Regras.java │ └── parser │ ├── Enquanto.g4 │ ├── EnquantoBaseListener.java │ ├── EnquantoLexer.java │ ├── EnquantoListener.java │ └── EnquantoParser.java ├── teste.while ├── testes ├── escolha1.while ├── escolha2.while ├── escolha3.while ├── funcao1.while ├── funcao2.while ├── funcao3.while ├── funcao4.while ├── para1.while ├── para2.while ├── para3.while ├── se1.while ├── se2.while └── se3.while ├── while ├── while.bat └── while.jar /.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | .idea/misc.xml 3 | .idea/workspace.xml 4 | 5 | *.interp 6 | *.tokens 7 | -------------------------------------------------------------------------------- /.gitpod.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM gitpod/workspace-full 2 | 3 | RUN bash -c ". /home/gitpod/.sdkman/bin/sdkman-init.sh && sdk install java 17.0.5-zulu" 4 | -------------------------------------------------------------------------------- /.gitpod.yml: -------------------------------------------------------------------------------- 1 | image: 2 | file: .gitpod.Dockerfile 3 | -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 28 | 29 | 31 | 32 | 37 | 38 | 39 | 41 | 42 | 44 | 45 | 46 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 84 | 85 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 1611415866342 105 | 111 | 112 | 113 | 114 | 116 | 117 | 118 | 119 | 120 | 121 | 123 | 124 | file://$PROJECT_DIR$/src/plp/enquanto/linguagem/Linguagem.java 125 | 136 126 | 128 | 129 | file://$PROJECT_DIR$/src/plp/enquanto/linguagem/Linguagem.java 130 | 130 131 | 133 | 134 | 135 | 136 | 137 | 138 | plp.enquanto.parser.* 139 | 140 | 141 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "Executar este programa", 6 | "request": "launch", 7 | "command": "java -jar while.jar ${file}", 8 | "type": "node-terminal" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | While 2 | ===== 3 | 4 | Linguagem "Enquanto" usada como exemplo na disciplina de Paradigmas de Linguagens de Programação 5 | 6 | > Implementação da linguagem em Scala (~250 linhas de código): [whilelang](http://github.com/lrlucena/whilelang) 7 | 8 | ## Sintaxe 9 | 10 | A gramática está definida em [Enquanto.g4](https://github.com/lrlucena/While/blob/master/src/plp/enquanto/parser/Enquanto.g4) 11 | 12 | ### Exemplo 13 | 14 |
15 | a := leia;
16 | b := 10;
17 | se a <= b entao
18 |   exiba "Menor"
19 | senao
20 |   exiba "Maior"
21 | 
22 | 23 | ## Compilação e Execução 24 | 25 | Este projeto usa alguns recursos da versão 14 de Java. Por isso é necessário verificar a versão instalada e, se for necessário, atualizar a versão. 26 | 27 | ````bash 28 | $ java -version 29 | ```` 30 | 31 | Caso seja necessário, você pode usar o sdkman (sdkman.org) para instalar a versão mais nova. 32 | 33 | ````bash 34 | $ sdk i java 35 | ```` 36 | 37 | Para compilar use `compilar.bat` (windows) ou `compilar.sh` (linux). 38 | 39 | ````bash 40 | $ ./compilar.sh 41 | ```` 42 | O script gera o parser e compila o código Java gerado. 43 | 44 | Para executar use `while.bat` (windows) ou `./while` (linux). 45 | 46 | ````bash 47 | $ ./while olamundo.while 48 | ```` 49 | 50 | ## Projeto de Paradigmas de Linguagens de Programação 51 | 52 | ### Tarefas: 53 | 1. Inclua a operações de divisão (`/`) e de exponenciação de inteiros (`^`) 54 | 2. Inclua as operações `ou` e `xor` entre booleanos 55 | 3. Inclua as relações menor (`<`), maior (`>`), maior ou igual (`>=`) e diferente (`<>`) entre inteiros 56 | 4. Altere a sintaxe para que o `;` ao invés de separar comandos seja usado para finalizar cada comando 57 | 5. Crie o comando `para ID de expressao ate expressao faca comando`. Exemplo 58 |
59 |     para i de 1 ate 5 faca
60 |       escreva i
61 | 
62 | 6. Crie o comando `repita expressao vezes comando`. Exemplo 63 |
64 |     repita 10 vezes
65 |       exiba "Funciona"
66 | 
67 | 7. Altere o comando `se .. entao .. senao ...` para incluir a cláusula `senaose`. Cada `se` pode ter zero ou mais clausulas `senaose`. Exemplo: 68 |
69 |     se nota >= 6 entao
70 |       exiba "Aprovado"
71 |     senaose nota >= 3 entao
72 |       exiba "Recuperação"
73 |     senao
74 |       exiba "Reprovado"
75 | 
76 | 77 | 8. Crie o comando `escolha` (switch). 78 |
79 |     x = leia
80 |     escolha x
81 |       1 : exiba "um"
82 |       2 : exiba "dois"
83 |       _ : exiba "outro numero"
84 | 
85 | 86 | 9. Altere a linguagem para permitir atribuições paralelas: 87 |
88 |     a, b, c := 2, 3, 4
89 |     a, b := b, a
90 | 
91 | 92 | 10. Altere a linguagem para que o comando `exiba` passa ser usado com números e com textos. 93 |
94 |   exiba "Ola Mundo"
95 |   exiba 2021
96 | 
97 | -------------------------------------------------------------------------------- /While.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-leap-day -------------------------------------------------------------------------------- /compilar.bat: -------------------------------------------------------------------------------- 1 | java -jar .\lib\antlr-4.13.1-complete.jar -package plp.enquanto.parser .\src\plp\enquanto\parser\Enquanto.g4 2 | javac -cp .\lib\antlr-runtime-4.13.1.jar -d bin .\src\plp\enquanto\parser\*.java .\src\plp\enquanto\*.java 3 | copy .\lib\antlr-runtime-4.13.1.jar while.jar 4 | jar --update --file .\while.jar --main-class plp.enquanto.Principal -C bin plp 5 | -------------------------------------------------------------------------------- /compilar.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | java -jar ./lib/antlr-4.13.1-complete.jar -package plp.enquanto.parser ./src/plp/enquanto/parser/Enquanto.g4 4 | javac -cp ./lib/antlr-runtime-4.13.1.jar -d bin ./src/plp/enquanto/parser/*.java ./src/plp/enquanto/*.java 5 | cp ./lib/antlr-runtime-4.13.1.jar while.jar 6 | jar --update --file ./while.jar --main-class plp.enquanto.Principal -C bin plp 7 | -------------------------------------------------------------------------------- /doc/README.md: -------------------------------------------------------------------------------- 1 | # Enquanto.g4 2 | 3 | ## Regras 4 | 5 | 1. programa 6 | 2. seqComando 7 | 3. comando 8 | 4. expressao 9 | 5. bool 10 | 6. INT 11 | 7. ID 12 | 8. Texto 13 | 9. Espaco 14 | 15 | - 16 | ### programa 17 | 18 | #### Text notation: 19 | 20 | ```antlr 21 | programa : seqComando ; 22 | ``` 23 | 24 | #### Visual notation: 25 | ![](images/programa.png) 26 | 27 | - 28 | ### seqComando 29 | 30 | #### Text notation: 31 | 32 | ```antlr 33 | seqComando : comando (';' comando)* ; 34 | ``` 35 | 36 | #### Visual notation: 37 | ![](images/seqComando.png) 38 | 39 | - 40 | ### comando 41 | 42 | #### Text notation: 43 | 44 | ```antlr 45 | comando : 46 | ID ':=' expressao # atribuicao 47 | | 'skip' # skip 48 | | 'se' bool 'entao' comando 'senao' comando # se 49 | | 'enquanto' bool 'faca' comando # enquanto 50 | | 'exiba' Texto # exiba 51 | | 'escreva' expressao # escreva 52 | | '{' seqComando '}' # bloco ; 53 | ``` 54 | 55 | #### Visual notation: 56 | ![](images/comando.png) 57 | 58 | - 59 | ### expressao 60 | 61 | #### Text notation: 62 | 63 | ```antlr 64 | expressao : 65 | INT # inteiro 66 | | 'leia' # leia 67 | | ID # id 68 | | expressao '*' expressao # opBin 69 | | expressao '+' expressao # opBin 70 | | expressao '-' expressao # opBin 71 | | '(' expressao ')' # expPar ; 72 | ``` 73 | 74 | #### Visual notation: 75 | ![](images/expressao.png) 76 | 77 | - 78 | ### bool 79 | 80 | #### Text notation: 81 | 82 | ```antlr 83 | bool : 84 | ('verdadeiro'|'falso') # booleano 85 | | expressao '=' expressao # opRel 86 | | expressao '<=' expressao # opRel 87 | | 'nao' bool # naoLogico 88 | | bool 'e' bool # eLogico 89 | | '(' bool ')' # boolPar ; 90 | ``` 91 | 92 | #### Visual notation: 93 | ![](images/bool.png) 94 | 95 | - 96 | ### INT 97 | 98 | #### Text notation: 99 | 100 | ```antlr 101 | INT : ('0'..'9')+ ; 102 | ``` 103 | 104 | #### Visual notation: 105 | ![](images/INT.png) 106 | 107 | - 108 | ### ID 109 | 110 | #### Text notation: 111 | 112 | ```antlr 113 | ID : ('a'..'z')+ ; 114 | ``` 115 | 116 | #### Visual notation: 117 | ![](images/ID.png) 118 | 119 | - 120 | ### Texto 121 | 122 | #### Text notation: 123 | 124 | ```antlr 125 | Texto : '"' .*? '"' ; 126 | ``` 127 | 128 | #### Visual notation: 129 | ![](images/Texto.png) 130 | 131 | - 132 | ### Espaco 133 | 134 | #### Text notation: 135 | 136 | ```antlr 137 | Espaco : [ \t\n\r] -> Skip ; 138 | ``` 139 | 140 | #### Visual notation: 141 | ![](images/Espaco.png) 142 | 143 | Generated by: [ANTLR 4 IDE](https://github.com/jknack/antlr4ide). Copyright (c) 2013 [Edgar Espina](https://twitter.com/edgarespina) 144 | -------------------------------------------------------------------------------- /doc/images/Espaco.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrlucena/while/92824b20e4f3125b26cff4c7cc180ceaab11080e/doc/images/Espaco.png -------------------------------------------------------------------------------- /doc/images/ID.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrlucena/while/92824b20e4f3125b26cff4c7cc180ceaab11080e/doc/images/ID.png -------------------------------------------------------------------------------- /doc/images/INT.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrlucena/while/92824b20e4f3125b26cff4c7cc180ceaab11080e/doc/images/INT.png -------------------------------------------------------------------------------- /doc/images/Texto.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrlucena/while/92824b20e4f3125b26cff4c7cc180ceaab11080e/doc/images/Texto.png -------------------------------------------------------------------------------- /doc/images/bool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrlucena/while/92824b20e4f3125b26cff4c7cc180ceaab11080e/doc/images/bool.png -------------------------------------------------------------------------------- /doc/images/comando.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrlucena/while/92824b20e4f3125b26cff4c7cc180ceaab11080e/doc/images/comando.png -------------------------------------------------------------------------------- /doc/images/expressao.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrlucena/while/92824b20e4f3125b26cff4c7cc180ceaab11080e/doc/images/expressao.png -------------------------------------------------------------------------------- /doc/images/programa.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrlucena/while/92824b20e4f3125b26cff4c7cc180ceaab11080e/doc/images/programa.png -------------------------------------------------------------------------------- /doc/images/seqComando.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrlucena/while/92824b20e4f3125b26cff4c7cc180ceaab11080e/doc/images/seqComando.png -------------------------------------------------------------------------------- /lib/antlr-4.13.1-complete.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrlucena/while/92824b20e4f3125b26cff4c7cc180ceaab11080e/lib/antlr-4.13.1-complete.jar -------------------------------------------------------------------------------- /lib/antlr-runtime-4.13.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrlucena/while/92824b20e4f3125b26cff4c7cc180ceaab11080e/lib/antlr-runtime-4.13.1.jar -------------------------------------------------------------------------------- /olamundo.while: -------------------------------------------------------------------------------- 1 | exiba "Ola Mundo!"; 2 | escreva 2000 + 21 3 | -------------------------------------------------------------------------------- /src/plp/enquanto/Linguagem.java: -------------------------------------------------------------------------------- 1 | package plp.enquanto; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | import java.util.Scanner; 7 | 8 | interface Linguagem { 9 | Map ambiente = new HashMap<>(); 10 | Scanner scanner = new Scanner(System.in); 11 | 12 | interface Bool { 13 | boolean getValor(); 14 | } 15 | 16 | interface Comando { 17 | void execute(); 18 | } 19 | 20 | interface Expressao { 21 | int getValor(); 22 | } 23 | 24 | /* 25 | Comandos 26 | */ 27 | class Programa { 28 | private final List comandos; 29 | public Programa(List comandos) { 30 | this.comandos = comandos; 31 | } 32 | public void execute() { 33 | comandos.forEach(Comando::execute); 34 | } 35 | } 36 | 37 | class Se implements Comando { 38 | private final Bool condicao; 39 | private final Comando entao; 40 | private final Comando senao; 41 | 42 | public Se(Bool condicao, Comando entao, Comando senao) { 43 | this.condicao = condicao; 44 | this.entao = entao; 45 | this.senao = senao; 46 | } 47 | 48 | @Override 49 | public void execute() { 50 | if (condicao.getValor()) 51 | entao.execute(); 52 | else 53 | senao.execute(); 54 | } 55 | } 56 | 57 | Skip skip = new Skip(); 58 | class Skip implements Comando { 59 | @Override 60 | public void execute() {} 61 | } 62 | 63 | class Escreva implements Comando { 64 | private final Expressao exp; 65 | 66 | public Escreva(Expressao exp) { 67 | this.exp = exp; 68 | } 69 | 70 | @Override 71 | public void execute() { 72 | System.out.println(exp.getValor()); 73 | } 74 | } 75 | 76 | class Enquanto implements Comando { 77 | private final Bool condicao; 78 | private final Comando comando; 79 | 80 | public Enquanto(Bool condicao, Comando comando) { 81 | this.condicao = condicao; 82 | this.comando = comando; 83 | } 84 | 85 | @Override 86 | public void execute() { 87 | while (condicao.getValor()) { 88 | comando.execute(); 89 | } 90 | } 91 | } 92 | 93 | class Exiba implements Comando { 94 | private final String texto; 95 | 96 | public Exiba(String texto) { 97 | this.texto = texto; 98 | } 99 | 100 | @Override 101 | public void execute() { 102 | System.out.println(texto); 103 | } 104 | } 105 | 106 | class Bloco implements Comando { 107 | private final List comandos; 108 | 109 | public Bloco(List comandos) { 110 | this.comandos = comandos; 111 | } 112 | 113 | @Override 114 | public void execute() { 115 | comandos.forEach(Comando::execute); 116 | } 117 | } 118 | 119 | class Atribuicao implements Comando { 120 | private final String id; 121 | private final Expressao exp; 122 | 123 | Atribuicao(String id, Expressao exp) { 124 | this.id = id; 125 | this.exp = exp; 126 | } 127 | 128 | @Override 129 | public void execute() { 130 | ambiente.put(id, exp.getValor()); 131 | } 132 | } 133 | 134 | /* 135 | Expressoes 136 | */ 137 | 138 | abstract class OpBin { 139 | protected final T esq; 140 | protected final T dir; 141 | 142 | OpBin(T esq, T dir) { 143 | this.esq = esq; 144 | this.dir = dir; 145 | } 146 | } 147 | 148 | abstract class OpUnaria { 149 | protected final T operando; 150 | 151 | OpUnaria(T operando) { 152 | this.operando = operando; 153 | } 154 | } 155 | 156 | class Inteiro implements Expressao { 157 | private final int valor; 158 | 159 | Inteiro(int valor) { 160 | this.valor = valor; 161 | } 162 | 163 | @Override 164 | public int getValor() { 165 | return valor; 166 | } 167 | } 168 | 169 | class Id implements Expressao { 170 | private final String id; 171 | 172 | Id(String id) { 173 | this.id = id; 174 | } 175 | 176 | @Override 177 | public int getValor() { 178 | return ambiente.getOrDefault(id, 0); 179 | } 180 | } 181 | 182 | Leia leia = new Leia(); 183 | class Leia implements Expressao { 184 | @Override 185 | public int getValor() { 186 | return scanner.nextInt(); 187 | } 188 | } 189 | 190 | class ExpSoma extends OpBin implements Expressao { 191 | ExpSoma(Expressao esq, Expressao dir) { 192 | super(esq, dir); 193 | } 194 | 195 | @Override 196 | public int getValor() { 197 | return esq.getValor() + dir.getValor(); 198 | } 199 | } 200 | 201 | class ExpSub extends OpBin implements Expressao { 202 | ExpSub(Expressao esq, Expressao dir) { 203 | super(esq, dir); 204 | } 205 | 206 | @Override 207 | public int getValor() { 208 | return esq.getValor() - dir.getValor(); 209 | } 210 | } 211 | 212 | class ExpMult extends OpBin implements Expressao{ 213 | ExpMult(Expressao esq, Expressao dir) { 214 | super(esq, dir); 215 | } 216 | 217 | @Override 218 | public int getValor() { 219 | return esq.getValor() * dir.getValor(); 220 | } 221 | } 222 | 223 | class Booleano implements Bool { 224 | private final boolean valor; 225 | 226 | Booleano(boolean valor) { 227 | this.valor = valor; 228 | } 229 | 230 | @Override 231 | public boolean getValor() { 232 | return valor; 233 | } 234 | } 235 | 236 | class ExpIgual extends OpBin implements Bool { 237 | ExpIgual(Expressao esq, Expressao dir) { 238 | super(esq, dir); 239 | } 240 | 241 | @Override 242 | public boolean getValor() { 243 | return esq.getValor() == dir.getValor(); 244 | } 245 | } 246 | 247 | class ExpMenorIgual extends OpBin implements Bool{ 248 | ExpMenorIgual(Expressao esq, Expressao dir) { 249 | super(esq, dir); 250 | } 251 | 252 | @Override 253 | public boolean getValor() { 254 | return esq.getValor() <= dir.getValor(); 255 | } 256 | } 257 | 258 | class NaoLogico extends OpUnaria implements Bool{ 259 | NaoLogico(Bool operando) { 260 | super(operando); 261 | } 262 | 263 | @Override 264 | public boolean getValor() { 265 | return !operando.getValor(); 266 | } 267 | } 268 | 269 | class ELogico extends OpBin implements Bool{ 270 | ELogico(Bool esq, Bool dir) { 271 | super(esq, dir); 272 | } 273 | 274 | @Override 275 | public boolean getValor() { 276 | return esq.getValor() && dir.getValor(); 277 | } 278 | } 279 | } 280 | -------------------------------------------------------------------------------- /src/plp/enquanto/Principal.java: -------------------------------------------------------------------------------- 1 | package plp.enquanto; 2 | 3 | import java.io.IOException; 4 | import java.util.Scanner; 5 | 6 | import org.antlr.v4.runtime.CharStream; 7 | import org.antlr.v4.runtime.CharStreams; 8 | import org.antlr.v4.runtime.CommonTokenStream; 9 | import org.antlr.v4.runtime.tree.ParseTree; 10 | import org.antlr.v4.runtime.tree.ParseTreeWalker; 11 | 12 | import plp.enquanto.Linguagem.Programa; 13 | import plp.enquanto.parser.EnquantoLexer; 14 | import plp.enquanto.parser.EnquantoParser; 15 | 16 | public class Principal { 17 | 18 | private static ParseTree parse(String arq) { 19 | CharStream input; 20 | try { 21 | input = CharStreams.fromFileName(arq); 22 | } catch (IOException e) { 23 | input = CharStreams.fromString("exiba \"Arquivo não encontrado.\""); 24 | } 25 | final EnquantoLexer lexer = new EnquantoLexer(input); 26 | final CommonTokenStream tokens = new CommonTokenStream(lexer); 27 | final EnquantoParser parser = new EnquantoParser(tokens); 28 | return parser.programa(); 29 | } 30 | 31 | public static void main(final String ... args) { 32 | final String arq; 33 | if (args.length > 0) { 34 | arq = args[0]; 35 | } else { 36 | System.out.print("Qual o arquivo para executar? "); 37 | Scanner scanner = new Scanner(System.in); 38 | arq = scanner.nextLine(); 39 | scanner.close(); 40 | } 41 | final ParseTree tree = parse(arq); 42 | final ParseTreeWalker walker = new ParseTreeWalker(); 43 | final Regras regras = new Regras(); 44 | walker.walk(regras, tree); 45 | Programa programa = regras.getPrograma(); 46 | programa.execute(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/plp/enquanto/Propriedades.java: -------------------------------------------------------------------------------- 1 | package plp.enquanto; 2 | 3 | import org.antlr.v4.runtime.tree.ParseTree; 4 | import org.antlr.v4.runtime.tree.ParseTreeProperty; 5 | 6 | public class Propriedades { 7 | private final ParseTreeProperty valores; 8 | 9 | public Propriedades() { 10 | valores = new ParseTreeProperty<>(); 11 | } 12 | 13 | @SuppressWarnings(value = "unchecked") 14 | public T pegue(ParseTree node) { 15 | T valor = (T) valores.get(node); 16 | valores.removeFrom(node); 17 | return valor; 18 | } 19 | 20 | public void insira(ParseTree node, T valor) { 21 | valores.put(node, valor); 22 | } 23 | } -------------------------------------------------------------------------------- /src/plp/enquanto/Regras.java: -------------------------------------------------------------------------------- 1 | package plp.enquanto; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import plp.enquanto.Linguagem.*; 7 | import plp.enquanto.parser.EnquantoBaseListener; 8 | import plp.enquanto.parser.EnquantoParser.*; 9 | 10 | import static java.lang.Integer.parseInt; 11 | 12 | public class Regras extends EnquantoBaseListener { 13 | private final Leia leia; 14 | private final Skip skip; 15 | private final Propriedades valores; 16 | 17 | private Programa programa; 18 | 19 | public Regras() { 20 | leia = new Leia(); 21 | skip = new Skip(); 22 | valores = new Propriedades(); 23 | } 24 | 25 | public Programa getPrograma() { 26 | return programa; 27 | } 28 | 29 | @Override 30 | public void exitBool(BoolContext ctx) { 31 | valores.insira(ctx, new Booleano("verdadeiro".equals(ctx.getText()))); 32 | } 33 | 34 | @Override 35 | public void exitLeia(LeiaContext ctx) { 36 | valores.insira(ctx, leia); 37 | } 38 | 39 | @Override 40 | public void exitSe(SeContext ctx) { 41 | final Bool condicao = valores.pegue(ctx.booleano()); 42 | final Comando entao = valores.pegue(ctx.comando(0)); 43 | final Comando senao = valores.pegue(ctx.comando(1)); 44 | valores.insira(ctx, new Se(condicao, entao, senao)); 45 | } 46 | 47 | @Override 48 | public void exitInteiro(InteiroContext ctx) { 49 | valores.insira(ctx, new Inteiro(parseInt(ctx.getText()))); 50 | } 51 | 52 | @Override 53 | public void exitSkip(SkipContext ctx) { 54 | valores.insira(ctx, skip); 55 | } 56 | 57 | @Override 58 | public void exitEscreva(EscrevaContext ctx) { 59 | final Expressao exp = valores.pegue(ctx.expressao()); 60 | valores.insira(ctx, new Escreva(exp)); 61 | } 62 | 63 | @Override 64 | public void exitPrograma(ProgramaContext ctx) { 65 | final List cmds = valores.pegue(ctx.seqComando()); 66 | programa = new Programa(cmds); 67 | valores.insira(ctx, programa); 68 | } 69 | 70 | @Override 71 | public void exitId(IdContext ctx) { 72 | final String id = ctx.ID().getText(); 73 | valores.insira(ctx, new Id(id)); 74 | } 75 | 76 | @Override 77 | public void exitSeqComando(SeqComandoContext ctx) { 78 | final List comandos = new ArrayList<>(); 79 | for (ComandoContext c : ctx.comando()) { 80 | comandos.add(valores.pegue(c)); 81 | } 82 | valores.insira(ctx, comandos); 83 | } 84 | 85 | @Override 86 | public void exitAtribuicao(AtribuicaoContext ctx) { 87 | final String id = ctx.ID().getText(); 88 | final Expressao exp = valores.pegue(ctx.expressao()); 89 | valores.insira(ctx, new Atribuicao(id, exp)); 90 | } 91 | 92 | @Override 93 | public void exitBloco(BlocoContext ctx) { 94 | final List cmds = valores.pegue(ctx.seqComando()); 95 | valores.insira(ctx, new Bloco(cmds)); 96 | } 97 | 98 | @Override 99 | public void exitOpBin(OpBinContext ctx) { 100 | final Expressao esq = valores.pegue(ctx.expressao(0)); 101 | final Expressao dir = valores.pegue(ctx.expressao(1)); 102 | final String op = ctx.getChild(1).getText(); 103 | final Expressao exp = switch (op) { 104 | case "*" -> new ExpMult(esq, dir); 105 | case "-" -> new ExpSub(esq, dir); 106 | default -> new ExpSoma(esq, dir); 107 | }; 108 | valores.insira(ctx, exp); 109 | } 110 | 111 | @Override 112 | public void exitEnquanto(EnquantoContext ctx) { 113 | final Bool condicao = valores.pegue(ctx.booleano()); 114 | final Comando comando = valores.pegue(ctx.comando()); 115 | valores.insira(ctx, new Enquanto(condicao, comando)); 116 | } 117 | 118 | @Override 119 | public void exitELogico(ELogicoContext ctx) { 120 | final Bool esq = valores.pegue(ctx.booleano(0)); 121 | final Bool dir = valores.pegue(ctx.booleano(1)); 122 | valores.insira(ctx, new ELogico(esq, dir)); 123 | } 124 | 125 | @Override 126 | public void exitBoolPar(BoolParContext ctx) { 127 | final Bool booleano = valores.pegue(ctx.booleano()); 128 | valores.insira(ctx, booleano); 129 | } 130 | 131 | @Override 132 | public void exitNaoLogico(NaoLogicoContext ctx) { 133 | final Bool b = valores.pegue(ctx.booleano()); 134 | valores.insira(ctx, new NaoLogico(b)); 135 | } 136 | 137 | @Override 138 | public void exitExpPar(ExpParContext ctx) { 139 | final Expressao exp = valores.pegue(ctx.expressao()); 140 | valores.insira(ctx, exp); 141 | } 142 | 143 | @Override 144 | public void exitExiba(ExibaContext ctx) { 145 | final String t = ctx.TEXTO().getText(); 146 | final String texto = t.substring(1, t.length() - 1); 147 | valores.insira(ctx, new Exiba(texto)); 148 | } 149 | 150 | @Override 151 | public void exitOpRel(OpRelContext ctx) { 152 | final Expressao esq = valores.pegue(ctx.expressao(0)); 153 | final Expressao dir = valores.pegue(ctx.expressao(1)); 154 | final String op = ctx.getChild(1).getText(); 155 | final Bool exp = switch (op) { 156 | case "=" -> new ExpIgual(esq, dir); 157 | case "<=" -> new ExpMenorIgual(esq, dir); 158 | default -> new ExpIgual(esq, esq); 159 | }; 160 | valores.insira(ctx, exp); 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /src/plp/enquanto/parser/Enquanto.g4: -------------------------------------------------------------------------------- 1 | grammar Enquanto; 2 | 3 | programa : seqComando; // sequência de comandos 4 | 5 | seqComando: comando (';' comando)* ; 6 | 7 | comando: ID ':=' expressao # atribuicao 8 | | 'skip' # skip 9 | | 'se' booleano 'entao' comando 'senao' comando # se 10 | | 'enquanto' booleano 'faca' comando # enquanto 11 | | 'exiba' TEXTO # exiba 12 | | 'escreva' expressao # escreva 13 | | '{' seqComando '}' # bloco 14 | ; 15 | 16 | expressao: INT # inteiro 17 | | 'leia' # leia 18 | | ID # id 19 | | expressao '*' expressao # opBin 20 | | expressao ('+' | '-') expressao # opBin 21 | | '(' expressao ')' # expPar 22 | ; 23 | 24 | booleano: BOOLEANO # bool 25 | | expressao '=' expressao # opRel 26 | | expressao '<=' expressao # opRel 27 | | 'nao' booleano # naoLogico 28 | | booleano 'e' booleano # eLogico 29 | | '(' booleano ')' # boolPar 30 | ; 31 | 32 | 33 | BOOLEANO: 'verdadeiro' | 'falso'; 34 | INT: ('0'..'9')+ ; 35 | ID: ('a'..'z')+; 36 | TEXTO: '"' .*? '"'; 37 | 38 | Comentario: '#' .*? '\n' -> skip; 39 | Espaco: [ \t\n\r] -> skip; -------------------------------------------------------------------------------- /src/plp/enquanto/parser/EnquantoBaseListener.java: -------------------------------------------------------------------------------- 1 | // Generated from ./src/plp/enquanto/parser/Enquanto.g4 by ANTLR 4.13.1 2 | package plp.enquanto.parser; 3 | 4 | import org.antlr.v4.runtime.ParserRuleContext; 5 | import org.antlr.v4.runtime.tree.ErrorNode; 6 | import org.antlr.v4.runtime.tree.TerminalNode; 7 | 8 | /** 9 | * This class provides an empty implementation of {@link EnquantoListener}, 10 | * which can be extended to create a listener which only needs to handle a subset 11 | * of the available methods. 12 | */ 13 | @SuppressWarnings("CheckReturnValue") 14 | public class EnquantoBaseListener implements EnquantoListener { 15 | /** 16 | * {@inheritDoc} 17 | * 18 | *

The default implementation does nothing.

19 | */ 20 | @Override public void enterPrograma(EnquantoParser.ProgramaContext ctx) { } 21 | /** 22 | * {@inheritDoc} 23 | * 24 | *

The default implementation does nothing.

25 | */ 26 | @Override public void exitPrograma(EnquantoParser.ProgramaContext ctx) { } 27 | /** 28 | * {@inheritDoc} 29 | * 30 | *

The default implementation does nothing.

31 | */ 32 | @Override public void enterSeqComando(EnquantoParser.SeqComandoContext ctx) { } 33 | /** 34 | * {@inheritDoc} 35 | * 36 | *

The default implementation does nothing.

37 | */ 38 | @Override public void exitSeqComando(EnquantoParser.SeqComandoContext ctx) { } 39 | /** 40 | * {@inheritDoc} 41 | * 42 | *

The default implementation does nothing.

43 | */ 44 | @Override public void enterAtribuicao(EnquantoParser.AtribuicaoContext ctx) { } 45 | /** 46 | * {@inheritDoc} 47 | * 48 | *

The default implementation does nothing.

49 | */ 50 | @Override public void exitAtribuicao(EnquantoParser.AtribuicaoContext ctx) { } 51 | /** 52 | * {@inheritDoc} 53 | * 54 | *

The default implementation does nothing.

55 | */ 56 | @Override public void enterSkip(EnquantoParser.SkipContext ctx) { } 57 | /** 58 | * {@inheritDoc} 59 | * 60 | *

The default implementation does nothing.

61 | */ 62 | @Override public void exitSkip(EnquantoParser.SkipContext ctx) { } 63 | /** 64 | * {@inheritDoc} 65 | * 66 | *

The default implementation does nothing.

67 | */ 68 | @Override public void enterSe(EnquantoParser.SeContext ctx) { } 69 | /** 70 | * {@inheritDoc} 71 | * 72 | *

The default implementation does nothing.

73 | */ 74 | @Override public void exitSe(EnquantoParser.SeContext ctx) { } 75 | /** 76 | * {@inheritDoc} 77 | * 78 | *

The default implementation does nothing.

79 | */ 80 | @Override public void enterEnquanto(EnquantoParser.EnquantoContext ctx) { } 81 | /** 82 | * {@inheritDoc} 83 | * 84 | *

The default implementation does nothing.

85 | */ 86 | @Override public void exitEnquanto(EnquantoParser.EnquantoContext ctx) { } 87 | /** 88 | * {@inheritDoc} 89 | * 90 | *

The default implementation does nothing.

91 | */ 92 | @Override public void enterExiba(EnquantoParser.ExibaContext ctx) { } 93 | /** 94 | * {@inheritDoc} 95 | * 96 | *

The default implementation does nothing.

97 | */ 98 | @Override public void exitExiba(EnquantoParser.ExibaContext ctx) { } 99 | /** 100 | * {@inheritDoc} 101 | * 102 | *

The default implementation does nothing.

103 | */ 104 | @Override public void enterEscreva(EnquantoParser.EscrevaContext ctx) { } 105 | /** 106 | * {@inheritDoc} 107 | * 108 | *

The default implementation does nothing.

109 | */ 110 | @Override public void exitEscreva(EnquantoParser.EscrevaContext ctx) { } 111 | /** 112 | * {@inheritDoc} 113 | * 114 | *

The default implementation does nothing.

115 | */ 116 | @Override public void enterBloco(EnquantoParser.BlocoContext ctx) { } 117 | /** 118 | * {@inheritDoc} 119 | * 120 | *

The default implementation does nothing.

121 | */ 122 | @Override public void exitBloco(EnquantoParser.BlocoContext ctx) { } 123 | /** 124 | * {@inheritDoc} 125 | * 126 | *

The default implementation does nothing.

127 | */ 128 | @Override public void enterLeia(EnquantoParser.LeiaContext ctx) { } 129 | /** 130 | * {@inheritDoc} 131 | * 132 | *

The default implementation does nothing.

133 | */ 134 | @Override public void exitLeia(EnquantoParser.LeiaContext ctx) { } 135 | /** 136 | * {@inheritDoc} 137 | * 138 | *

The default implementation does nothing.

139 | */ 140 | @Override public void enterInteiro(EnquantoParser.InteiroContext ctx) { } 141 | /** 142 | * {@inheritDoc} 143 | * 144 | *

The default implementation does nothing.

145 | */ 146 | @Override public void exitInteiro(EnquantoParser.InteiroContext ctx) { } 147 | /** 148 | * {@inheritDoc} 149 | * 150 | *

The default implementation does nothing.

151 | */ 152 | @Override public void enterOpBin(EnquantoParser.OpBinContext ctx) { } 153 | /** 154 | * {@inheritDoc} 155 | * 156 | *

The default implementation does nothing.

157 | */ 158 | @Override public void exitOpBin(EnquantoParser.OpBinContext ctx) { } 159 | /** 160 | * {@inheritDoc} 161 | * 162 | *

The default implementation does nothing.

163 | */ 164 | @Override public void enterId(EnquantoParser.IdContext ctx) { } 165 | /** 166 | * {@inheritDoc} 167 | * 168 | *

The default implementation does nothing.

169 | */ 170 | @Override public void exitId(EnquantoParser.IdContext ctx) { } 171 | /** 172 | * {@inheritDoc} 173 | * 174 | *

The default implementation does nothing.

175 | */ 176 | @Override public void enterExpPar(EnquantoParser.ExpParContext ctx) { } 177 | /** 178 | * {@inheritDoc} 179 | * 180 | *

The default implementation does nothing.

181 | */ 182 | @Override public void exitExpPar(EnquantoParser.ExpParContext ctx) { } 183 | /** 184 | * {@inheritDoc} 185 | * 186 | *

The default implementation does nothing.

187 | */ 188 | @Override public void enterBool(EnquantoParser.BoolContext ctx) { } 189 | /** 190 | * {@inheritDoc} 191 | * 192 | *

The default implementation does nothing.

193 | */ 194 | @Override public void exitBool(EnquantoParser.BoolContext ctx) { } 195 | /** 196 | * {@inheritDoc} 197 | * 198 | *

The default implementation does nothing.

199 | */ 200 | @Override public void enterELogico(EnquantoParser.ELogicoContext ctx) { } 201 | /** 202 | * {@inheritDoc} 203 | * 204 | *

The default implementation does nothing.

205 | */ 206 | @Override public void exitELogico(EnquantoParser.ELogicoContext ctx) { } 207 | /** 208 | * {@inheritDoc} 209 | * 210 | *

The default implementation does nothing.

211 | */ 212 | @Override public void enterNaoLogico(EnquantoParser.NaoLogicoContext ctx) { } 213 | /** 214 | * {@inheritDoc} 215 | * 216 | *

The default implementation does nothing.

217 | */ 218 | @Override public void exitNaoLogico(EnquantoParser.NaoLogicoContext ctx) { } 219 | /** 220 | * {@inheritDoc} 221 | * 222 | *

The default implementation does nothing.

223 | */ 224 | @Override public void enterOpRel(EnquantoParser.OpRelContext ctx) { } 225 | /** 226 | * {@inheritDoc} 227 | * 228 | *

The default implementation does nothing.

229 | */ 230 | @Override public void exitOpRel(EnquantoParser.OpRelContext ctx) { } 231 | /** 232 | * {@inheritDoc} 233 | * 234 | *

The default implementation does nothing.

235 | */ 236 | @Override public void enterBoolPar(EnquantoParser.BoolParContext ctx) { } 237 | /** 238 | * {@inheritDoc} 239 | * 240 | *

The default implementation does nothing.

241 | */ 242 | @Override public void exitBoolPar(EnquantoParser.BoolParContext ctx) { } 243 | 244 | /** 245 | * {@inheritDoc} 246 | * 247 | *

The default implementation does nothing.

248 | */ 249 | @Override public void enterEveryRule(ParserRuleContext ctx) { } 250 | /** 251 | * {@inheritDoc} 252 | * 253 | *

The default implementation does nothing.

254 | */ 255 | @Override public void exitEveryRule(ParserRuleContext ctx) { } 256 | /** 257 | * {@inheritDoc} 258 | * 259 | *

The default implementation does nothing.

260 | */ 261 | @Override public void visitTerminal(TerminalNode node) { } 262 | /** 263 | * {@inheritDoc} 264 | * 265 | *

The default implementation does nothing.

266 | */ 267 | @Override public void visitErrorNode(ErrorNode node) { } 268 | } -------------------------------------------------------------------------------- /src/plp/enquanto/parser/EnquantoLexer.java: -------------------------------------------------------------------------------- 1 | // Generated from ./src/plp/enquanto/parser/Enquanto.g4 by ANTLR 4.13.1 2 | package plp.enquanto.parser; 3 | import org.antlr.v4.runtime.Lexer; 4 | import org.antlr.v4.runtime.CharStream; 5 | import org.antlr.v4.runtime.Token; 6 | import org.antlr.v4.runtime.TokenStream; 7 | import org.antlr.v4.runtime.*; 8 | import org.antlr.v4.runtime.atn.*; 9 | import org.antlr.v4.runtime.dfa.DFA; 10 | import org.antlr.v4.runtime.misc.*; 11 | 12 | @SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue", "this-escape"}) 13 | public class EnquantoLexer extends Lexer { 14 | static { RuntimeMetaData.checkVersion("4.13.1", RuntimeMetaData.VERSION); } 15 | 16 | protected static final DFA[] _decisionToDFA; 17 | protected static final PredictionContextCache _sharedContextCache = 18 | new PredictionContextCache(); 19 | public static final int 20 | T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, T__5=6, T__6=7, T__7=8, T__8=9, 21 | T__9=10, T__10=11, T__11=12, T__12=13, T__13=14, T__14=15, T__15=16, T__16=17, 22 | T__17=18, T__18=19, T__19=20, T__20=21, T__21=22, BOOLEANO=23, INT=24, 23 | ID=25, TEXTO=26, Comentario=27, Espaco=28; 24 | public static String[] channelNames = { 25 | "DEFAULT_TOKEN_CHANNEL", "HIDDEN" 26 | }; 27 | 28 | public static String[] modeNames = { 29 | "DEFAULT_MODE" 30 | }; 31 | 32 | private static String[] makeRuleNames() { 33 | return new String[] { 34 | "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6", "T__7", "T__8", 35 | "T__9", "T__10", "T__11", "T__12", "T__13", "T__14", "T__15", "T__16", 36 | "T__17", "T__18", "T__19", "T__20", "T__21", "BOOLEANO", "INT", "ID", 37 | "TEXTO", "Comentario", "Espaco" 38 | }; 39 | } 40 | public static final String[] ruleNames = makeRuleNames(); 41 | 42 | private static String[] makeLiteralNames() { 43 | return new String[] { 44 | null, "';'", "':='", "'skip'", "'se'", "'entao'", "'senao'", "'enquanto'", 45 | "'faca'", "'exiba'", "'escreva'", "'{'", "'}'", "'leia'", "'*'", "'+'", 46 | "'-'", "'('", "')'", "'='", "'<='", "'nao'", "'e'" 47 | }; 48 | } 49 | private static final String[] _LITERAL_NAMES = makeLiteralNames(); 50 | private static String[] makeSymbolicNames() { 51 | return new String[] { 52 | null, null, null, null, null, null, null, null, null, null, null, null, 53 | null, null, null, null, null, null, null, null, null, null, null, "BOOLEANO", 54 | "INT", "ID", "TEXTO", "Comentario", "Espaco" 55 | }; 56 | } 57 | private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames(); 58 | public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES); 59 | 60 | /** 61 | * @deprecated Use {@link #VOCABULARY} instead. 62 | */ 63 | @Deprecated 64 | public static final String[] tokenNames; 65 | static { 66 | tokenNames = new String[_SYMBOLIC_NAMES.length]; 67 | for (int i = 0; i < tokenNames.length; i++) { 68 | tokenNames[i] = VOCABULARY.getLiteralName(i); 69 | if (tokenNames[i] == null) { 70 | tokenNames[i] = VOCABULARY.getSymbolicName(i); 71 | } 72 | 73 | if (tokenNames[i] == null) { 74 | tokenNames[i] = ""; 75 | } 76 | } 77 | } 78 | 79 | @Override 80 | @Deprecated 81 | public String[] getTokenNames() { 82 | return tokenNames; 83 | } 84 | 85 | @Override 86 | 87 | public Vocabulary getVocabulary() { 88 | return VOCABULARY; 89 | } 90 | 91 | 92 | public EnquantoLexer(CharStream input) { 93 | super(input); 94 | _interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache); 95 | } 96 | 97 | @Override 98 | public String getGrammarFileName() { return "Enquanto.g4"; } 99 | 100 | @Override 101 | public String[] getRuleNames() { return ruleNames; } 102 | 103 | @Override 104 | public String getSerializedATN() { return _serializedATN; } 105 | 106 | @Override 107 | public String[] getChannelNames() { return channelNames; } 108 | 109 | @Override 110 | public String[] getModeNames() { return modeNames; } 111 | 112 | @Override 113 | public ATN getATN() { return _ATN; } 114 | 115 | public static final String _serializedATN = 116 | "\u0004\u0000\u001c\u00bf\u0006\uffff\uffff\u0002\u0000\u0007\u0000\u0002"+ 117 | "\u0001\u0007\u0001\u0002\u0002\u0007\u0002\u0002\u0003\u0007\u0003\u0002"+ 118 | "\u0004\u0007\u0004\u0002\u0005\u0007\u0005\u0002\u0006\u0007\u0006\u0002"+ 119 | "\u0007\u0007\u0007\u0002\b\u0007\b\u0002\t\u0007\t\u0002\n\u0007\n\u0002"+ 120 | "\u000b\u0007\u000b\u0002\f\u0007\f\u0002\r\u0007\r\u0002\u000e\u0007\u000e"+ 121 | "\u0002\u000f\u0007\u000f\u0002\u0010\u0007\u0010\u0002\u0011\u0007\u0011"+ 122 | "\u0002\u0012\u0007\u0012\u0002\u0013\u0007\u0013\u0002\u0014\u0007\u0014"+ 123 | "\u0002\u0015\u0007\u0015\u0002\u0016\u0007\u0016\u0002\u0017\u0007\u0017"+ 124 | "\u0002\u0018\u0007\u0018\u0002\u0019\u0007\u0019\u0002\u001a\u0007\u001a"+ 125 | "\u0002\u001b\u0007\u001b\u0001\u0000\u0001\u0000\u0001\u0001\u0001\u0001"+ 126 | "\u0001\u0001\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002"+ 127 | "\u0001\u0003\u0001\u0003\u0001\u0003\u0001\u0004\u0001\u0004\u0001\u0004"+ 128 | "\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0005\u0001\u0005\u0001\u0005"+ 129 | "\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0006\u0001\u0006\u0001\u0006"+ 130 | "\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006"+ 131 | "\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\b\u0001"+ 132 | "\b\u0001\b\u0001\b\u0001\b\u0001\b\u0001\t\u0001\t\u0001\t\u0001\t\u0001"+ 133 | "\t\u0001\t\u0001\t\u0001\t\u0001\n\u0001\n\u0001\u000b\u0001\u000b\u0001"+ 134 | "\f\u0001\f\u0001\f\u0001\f\u0001\f\u0001\r\u0001\r\u0001\u000e\u0001\u000e"+ 135 | "\u0001\u000f\u0001\u000f\u0001\u0010\u0001\u0010\u0001\u0011\u0001\u0011"+ 136 | "\u0001\u0012\u0001\u0012\u0001\u0013\u0001\u0013\u0001\u0013\u0001\u0014"+ 137 | "\u0001\u0014\u0001\u0014\u0001\u0014\u0001\u0015\u0001\u0015\u0001\u0016"+ 138 | "\u0001\u0016\u0001\u0016\u0001\u0016\u0001\u0016\u0001\u0016\u0001\u0016"+ 139 | "\u0001\u0016\u0001\u0016\u0001\u0016\u0001\u0016\u0001\u0016\u0001\u0016"+ 140 | "\u0001\u0016\u0001\u0016\u0003\u0016\u009c\b\u0016\u0001\u0017\u0004\u0017"+ 141 | "\u009f\b\u0017\u000b\u0017\f\u0017\u00a0\u0001\u0018\u0004\u0018\u00a4"+ 142 | "\b\u0018\u000b\u0018\f\u0018\u00a5\u0001\u0019\u0001\u0019\u0005\u0019"+ 143 | "\u00aa\b\u0019\n\u0019\f\u0019\u00ad\t\u0019\u0001\u0019\u0001\u0019\u0001"+ 144 | "\u001a\u0001\u001a\u0005\u001a\u00b3\b\u001a\n\u001a\f\u001a\u00b6\t\u001a"+ 145 | "\u0001\u001a\u0001\u001a\u0001\u001a\u0001\u001a\u0001\u001b\u0001\u001b"+ 146 | "\u0001\u001b\u0001\u001b\u0002\u00ab\u00b4\u0000\u001c\u0001\u0001\u0003"+ 147 | "\u0002\u0005\u0003\u0007\u0004\t\u0005\u000b\u0006\r\u0007\u000f\b\u0011"+ 148 | "\t\u0013\n\u0015\u000b\u0017\f\u0019\r\u001b\u000e\u001d\u000f\u001f\u0010"+ 149 | "!\u0011#\u0012%\u0013\'\u0014)\u0015+\u0016-\u0017/\u00181\u00193\u001a"+ 150 | "5\u001b7\u001c\u0001\u0000\u0001\u0003\u0000\t\n\r\r \u00c3\u0000\u0001"+ 151 | "\u0001\u0000\u0000\u0000\u0000\u0003\u0001\u0000\u0000\u0000\u0000\u0005"+ 152 | "\u0001\u0000\u0000\u0000\u0000\u0007\u0001\u0000\u0000\u0000\u0000\t\u0001"+ 153 | "\u0000\u0000\u0000\u0000\u000b\u0001\u0000\u0000\u0000\u0000\r\u0001\u0000"+ 154 | "\u0000\u0000\u0000\u000f\u0001\u0000\u0000\u0000\u0000\u0011\u0001\u0000"+ 155 | "\u0000\u0000\u0000\u0013\u0001\u0000\u0000\u0000\u0000\u0015\u0001\u0000"+ 156 | "\u0000\u0000\u0000\u0017\u0001\u0000\u0000\u0000\u0000\u0019\u0001\u0000"+ 157 | "\u0000\u0000\u0000\u001b\u0001\u0000\u0000\u0000\u0000\u001d\u0001\u0000"+ 158 | "\u0000\u0000\u0000\u001f\u0001\u0000\u0000\u0000\u0000!\u0001\u0000\u0000"+ 159 | "\u0000\u0000#\u0001\u0000\u0000\u0000\u0000%\u0001\u0000\u0000\u0000\u0000"+ 160 | "\'\u0001\u0000\u0000\u0000\u0000)\u0001\u0000\u0000\u0000\u0000+\u0001"+ 161 | "\u0000\u0000\u0000\u0000-\u0001\u0000\u0000\u0000\u0000/\u0001\u0000\u0000"+ 162 | "\u0000\u00001\u0001\u0000\u0000\u0000\u00003\u0001\u0000\u0000\u0000\u0000"+ 163 | "5\u0001\u0000\u0000\u0000\u00007\u0001\u0000\u0000\u0000\u00019\u0001"+ 164 | "\u0000\u0000\u0000\u0003;\u0001\u0000\u0000\u0000\u0005>\u0001\u0000\u0000"+ 165 | "\u0000\u0007C\u0001\u0000\u0000\u0000\tF\u0001\u0000\u0000\u0000\u000b"+ 166 | "L\u0001\u0000\u0000\u0000\rR\u0001\u0000\u0000\u0000\u000f[\u0001\u0000"+ 167 | "\u0000\u0000\u0011`\u0001\u0000\u0000\u0000\u0013f\u0001\u0000\u0000\u0000"+ 168 | "\u0015n\u0001\u0000\u0000\u0000\u0017p\u0001\u0000\u0000\u0000\u0019r"+ 169 | "\u0001\u0000\u0000\u0000\u001bw\u0001\u0000\u0000\u0000\u001dy\u0001\u0000"+ 170 | "\u0000\u0000\u001f{\u0001\u0000\u0000\u0000!}\u0001\u0000\u0000\u0000"+ 171 | "#\u007f\u0001\u0000\u0000\u0000%\u0081\u0001\u0000\u0000\u0000\'\u0083"+ 172 | "\u0001\u0000\u0000\u0000)\u0086\u0001\u0000\u0000\u0000+\u008a\u0001\u0000"+ 173 | "\u0000\u0000-\u009b\u0001\u0000\u0000\u0000/\u009e\u0001\u0000\u0000\u0000"+ 174 | "1\u00a3\u0001\u0000\u0000\u00003\u00a7\u0001\u0000\u0000\u00005\u00b0"+ 175 | "\u0001\u0000\u0000\u00007\u00bb\u0001\u0000\u0000\u00009:\u0005;\u0000"+ 176 | "\u0000:\u0002\u0001\u0000\u0000\u0000;<\u0005:\u0000\u0000<=\u0005=\u0000"+ 177 | "\u0000=\u0004\u0001\u0000\u0000\u0000>?\u0005s\u0000\u0000?@\u0005k\u0000"+ 178 | "\u0000@A\u0005i\u0000\u0000AB\u0005p\u0000\u0000B\u0006\u0001\u0000\u0000"+ 179 | "\u0000CD\u0005s\u0000\u0000DE\u0005e\u0000\u0000E\b\u0001\u0000\u0000"+ 180 | "\u0000FG\u0005e\u0000\u0000GH\u0005n\u0000\u0000HI\u0005t\u0000\u0000"+ 181 | "IJ\u0005a\u0000\u0000JK\u0005o\u0000\u0000K\n\u0001\u0000\u0000\u0000"+ 182 | "LM\u0005s\u0000\u0000MN\u0005e\u0000\u0000NO\u0005n\u0000\u0000OP\u0005"+ 183 | "a\u0000\u0000PQ\u0005o\u0000\u0000Q\f\u0001\u0000\u0000\u0000RS\u0005"+ 184 | "e\u0000\u0000ST\u0005n\u0000\u0000TU\u0005q\u0000\u0000UV\u0005u\u0000"+ 185 | "\u0000VW\u0005a\u0000\u0000WX\u0005n\u0000\u0000XY\u0005t\u0000\u0000"+ 186 | "YZ\u0005o\u0000\u0000Z\u000e\u0001\u0000\u0000\u0000[\\\u0005f\u0000\u0000"+ 187 | "\\]\u0005a\u0000\u0000]^\u0005c\u0000\u0000^_\u0005a\u0000\u0000_\u0010"+ 188 | "\u0001\u0000\u0000\u0000`a\u0005e\u0000\u0000ab\u0005x\u0000\u0000bc\u0005"+ 189 | "i\u0000\u0000cd\u0005b\u0000\u0000de\u0005a\u0000\u0000e\u0012\u0001\u0000"+ 190 | "\u0000\u0000fg\u0005e\u0000\u0000gh\u0005s\u0000\u0000hi\u0005c\u0000"+ 191 | "\u0000ij\u0005r\u0000\u0000jk\u0005e\u0000\u0000kl\u0005v\u0000\u0000"+ 192 | "lm\u0005a\u0000\u0000m\u0014\u0001\u0000\u0000\u0000no\u0005{\u0000\u0000"+ 193 | "o\u0016\u0001\u0000\u0000\u0000pq\u0005}\u0000\u0000q\u0018\u0001\u0000"+ 194 | "\u0000\u0000rs\u0005l\u0000\u0000st\u0005e\u0000\u0000tu\u0005i\u0000"+ 195 | "\u0000uv\u0005a\u0000\u0000v\u001a\u0001\u0000\u0000\u0000wx\u0005*\u0000"+ 196 | "\u0000x\u001c\u0001\u0000\u0000\u0000yz\u0005+\u0000\u0000z\u001e\u0001"+ 197 | "\u0000\u0000\u0000{|\u0005-\u0000\u0000| \u0001\u0000\u0000\u0000}~\u0005"+ 198 | "(\u0000\u0000~\"\u0001\u0000\u0000\u0000\u007f\u0080\u0005)\u0000\u0000"+ 199 | "\u0080$\u0001\u0000\u0000\u0000\u0081\u0082\u0005=\u0000\u0000\u0082&"+ 200 | "\u0001\u0000\u0000\u0000\u0083\u0084\u0005<\u0000\u0000\u0084\u0085\u0005"+ 201 | "=\u0000\u0000\u0085(\u0001\u0000\u0000\u0000\u0086\u0087\u0005n\u0000"+ 202 | "\u0000\u0087\u0088\u0005a\u0000\u0000\u0088\u0089\u0005o\u0000\u0000\u0089"+ 203 | "*\u0001\u0000\u0000\u0000\u008a\u008b\u0005e\u0000\u0000\u008b,\u0001"+ 204 | "\u0000\u0000\u0000\u008c\u008d\u0005v\u0000\u0000\u008d\u008e\u0005e\u0000"+ 205 | "\u0000\u008e\u008f\u0005r\u0000\u0000\u008f\u0090\u0005d\u0000\u0000\u0090"+ 206 | "\u0091\u0005a\u0000\u0000\u0091\u0092\u0005d\u0000\u0000\u0092\u0093\u0005"+ 207 | "e\u0000\u0000\u0093\u0094\u0005i\u0000\u0000\u0094\u0095\u0005r\u0000"+ 208 | "\u0000\u0095\u009c\u0005o\u0000\u0000\u0096\u0097\u0005f\u0000\u0000\u0097"+ 209 | "\u0098\u0005a\u0000\u0000\u0098\u0099\u0005l\u0000\u0000\u0099\u009a\u0005"+ 210 | "s\u0000\u0000\u009a\u009c\u0005o\u0000\u0000\u009b\u008c\u0001\u0000\u0000"+ 211 | "\u0000\u009b\u0096\u0001\u0000\u0000\u0000\u009c.\u0001\u0000\u0000\u0000"+ 212 | "\u009d\u009f\u000209\u0000\u009e\u009d\u0001\u0000\u0000\u0000\u009f\u00a0"+ 213 | "\u0001\u0000\u0000\u0000\u00a0\u009e\u0001\u0000\u0000\u0000\u00a0\u00a1"+ 214 | "\u0001\u0000\u0000\u0000\u00a10\u0001\u0000\u0000\u0000\u00a2\u00a4\u0002"+ 215 | "az\u0000\u00a3\u00a2\u0001\u0000\u0000\u0000\u00a4\u00a5\u0001\u0000\u0000"+ 216 | "\u0000\u00a5\u00a3\u0001\u0000\u0000\u0000\u00a5\u00a6\u0001\u0000\u0000"+ 217 | "\u0000\u00a62\u0001\u0000\u0000\u0000\u00a7\u00ab\u0005\"\u0000\u0000"+ 218 | "\u00a8\u00aa\t\u0000\u0000\u0000\u00a9\u00a8\u0001\u0000\u0000\u0000\u00aa"+ 219 | "\u00ad\u0001\u0000\u0000\u0000\u00ab\u00ac\u0001\u0000\u0000\u0000\u00ab"+ 220 | "\u00a9\u0001\u0000\u0000\u0000\u00ac\u00ae\u0001\u0000\u0000\u0000\u00ad"+ 221 | "\u00ab\u0001\u0000\u0000\u0000\u00ae\u00af\u0005\"\u0000\u0000\u00af4"+ 222 | "\u0001\u0000\u0000\u0000\u00b0\u00b4\u0005#\u0000\u0000\u00b1\u00b3\t"+ 223 | "\u0000\u0000\u0000\u00b2\u00b1\u0001\u0000\u0000\u0000\u00b3\u00b6\u0001"+ 224 | "\u0000\u0000\u0000\u00b4\u00b5\u0001\u0000\u0000\u0000\u00b4\u00b2\u0001"+ 225 | "\u0000\u0000\u0000\u00b5\u00b7\u0001\u0000\u0000\u0000\u00b6\u00b4\u0001"+ 226 | "\u0000\u0000\u0000\u00b7\u00b8\u0005\n\u0000\u0000\u00b8\u00b9\u0001\u0000"+ 227 | "\u0000\u0000\u00b9\u00ba\u0006\u001a\u0000\u0000\u00ba6\u0001\u0000\u0000"+ 228 | "\u0000\u00bb\u00bc\u0007\u0000\u0000\u0000\u00bc\u00bd\u0001\u0000\u0000"+ 229 | "\u0000\u00bd\u00be\u0006\u001b\u0000\u0000\u00be8\u0001\u0000\u0000\u0000"+ 230 | "\u0006\u0000\u009b\u00a0\u00a5\u00ab\u00b4\u0001\u0006\u0000\u0000"; 231 | public static final ATN _ATN = 232 | new ATNDeserializer().deserialize(_serializedATN.toCharArray()); 233 | static { 234 | _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()]; 235 | for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) { 236 | _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); 237 | } 238 | } 239 | } -------------------------------------------------------------------------------- /src/plp/enquanto/parser/EnquantoListener.java: -------------------------------------------------------------------------------- 1 | // Generated from ./src/plp/enquanto/parser/Enquanto.g4 by ANTLR 4.13.1 2 | package plp.enquanto.parser; 3 | import org.antlr.v4.runtime.tree.ParseTreeListener; 4 | 5 | /** 6 | * This interface defines a complete listener for a parse tree produced by 7 | * {@link EnquantoParser}. 8 | */ 9 | public interface EnquantoListener extends ParseTreeListener { 10 | /** 11 | * Enter a parse tree produced by {@link EnquantoParser#programa}. 12 | * @param ctx the parse tree 13 | */ 14 | void enterPrograma(EnquantoParser.ProgramaContext ctx); 15 | /** 16 | * Exit a parse tree produced by {@link EnquantoParser#programa}. 17 | * @param ctx the parse tree 18 | */ 19 | void exitPrograma(EnquantoParser.ProgramaContext ctx); 20 | /** 21 | * Enter a parse tree produced by {@link EnquantoParser#seqComando}. 22 | * @param ctx the parse tree 23 | */ 24 | void enterSeqComando(EnquantoParser.SeqComandoContext ctx); 25 | /** 26 | * Exit a parse tree produced by {@link EnquantoParser#seqComando}. 27 | * @param ctx the parse tree 28 | */ 29 | void exitSeqComando(EnquantoParser.SeqComandoContext ctx); 30 | /** 31 | * Enter a parse tree produced by the {@code atribuicao} 32 | * labeled alternative in {@link EnquantoParser#comando}. 33 | * @param ctx the parse tree 34 | */ 35 | void enterAtribuicao(EnquantoParser.AtribuicaoContext ctx); 36 | /** 37 | * Exit a parse tree produced by the {@code atribuicao} 38 | * labeled alternative in {@link EnquantoParser#comando}. 39 | * @param ctx the parse tree 40 | */ 41 | void exitAtribuicao(EnquantoParser.AtribuicaoContext ctx); 42 | /** 43 | * Enter a parse tree produced by the {@code skip} 44 | * labeled alternative in {@link EnquantoParser#comando}. 45 | * @param ctx the parse tree 46 | */ 47 | void enterSkip(EnquantoParser.SkipContext ctx); 48 | /** 49 | * Exit a parse tree produced by the {@code skip} 50 | * labeled alternative in {@link EnquantoParser#comando}. 51 | * @param ctx the parse tree 52 | */ 53 | void exitSkip(EnquantoParser.SkipContext ctx); 54 | /** 55 | * Enter a parse tree produced by the {@code se} 56 | * labeled alternative in {@link EnquantoParser#comando}. 57 | * @param ctx the parse tree 58 | */ 59 | void enterSe(EnquantoParser.SeContext ctx); 60 | /** 61 | * Exit a parse tree produced by the {@code se} 62 | * labeled alternative in {@link EnquantoParser#comando}. 63 | * @param ctx the parse tree 64 | */ 65 | void exitSe(EnquantoParser.SeContext ctx); 66 | /** 67 | * Enter a parse tree produced by the {@code enquanto} 68 | * labeled alternative in {@link EnquantoParser#comando}. 69 | * @param ctx the parse tree 70 | */ 71 | void enterEnquanto(EnquantoParser.EnquantoContext ctx); 72 | /** 73 | * Exit a parse tree produced by the {@code enquanto} 74 | * labeled alternative in {@link EnquantoParser#comando}. 75 | * @param ctx the parse tree 76 | */ 77 | void exitEnquanto(EnquantoParser.EnquantoContext ctx); 78 | /** 79 | * Enter a parse tree produced by the {@code exiba} 80 | * labeled alternative in {@link EnquantoParser#comando}. 81 | * @param ctx the parse tree 82 | */ 83 | void enterExiba(EnquantoParser.ExibaContext ctx); 84 | /** 85 | * Exit a parse tree produced by the {@code exiba} 86 | * labeled alternative in {@link EnquantoParser#comando}. 87 | * @param ctx the parse tree 88 | */ 89 | void exitExiba(EnquantoParser.ExibaContext ctx); 90 | /** 91 | * Enter a parse tree produced by the {@code escreva} 92 | * labeled alternative in {@link EnquantoParser#comando}. 93 | * @param ctx the parse tree 94 | */ 95 | void enterEscreva(EnquantoParser.EscrevaContext ctx); 96 | /** 97 | * Exit a parse tree produced by the {@code escreva} 98 | * labeled alternative in {@link EnquantoParser#comando}. 99 | * @param ctx the parse tree 100 | */ 101 | void exitEscreva(EnquantoParser.EscrevaContext ctx); 102 | /** 103 | * Enter a parse tree produced by the {@code bloco} 104 | * labeled alternative in {@link EnquantoParser#comando}. 105 | * @param ctx the parse tree 106 | */ 107 | void enterBloco(EnquantoParser.BlocoContext ctx); 108 | /** 109 | * Exit a parse tree produced by the {@code bloco} 110 | * labeled alternative in {@link EnquantoParser#comando}. 111 | * @param ctx the parse tree 112 | */ 113 | void exitBloco(EnquantoParser.BlocoContext ctx); 114 | /** 115 | * Enter a parse tree produced by the {@code leia} 116 | * labeled alternative in {@link EnquantoParser#expressao}. 117 | * @param ctx the parse tree 118 | */ 119 | void enterLeia(EnquantoParser.LeiaContext ctx); 120 | /** 121 | * Exit a parse tree produced by the {@code leia} 122 | * labeled alternative in {@link EnquantoParser#expressao}. 123 | * @param ctx the parse tree 124 | */ 125 | void exitLeia(EnquantoParser.LeiaContext ctx); 126 | /** 127 | * Enter a parse tree produced by the {@code inteiro} 128 | * labeled alternative in {@link EnquantoParser#expressao}. 129 | * @param ctx the parse tree 130 | */ 131 | void enterInteiro(EnquantoParser.InteiroContext ctx); 132 | /** 133 | * Exit a parse tree produced by the {@code inteiro} 134 | * labeled alternative in {@link EnquantoParser#expressao}. 135 | * @param ctx the parse tree 136 | */ 137 | void exitInteiro(EnquantoParser.InteiroContext ctx); 138 | /** 139 | * Enter a parse tree produced by the {@code opBin} 140 | * labeled alternative in {@link EnquantoParser#expressao}. 141 | * @param ctx the parse tree 142 | */ 143 | void enterOpBin(EnquantoParser.OpBinContext ctx); 144 | /** 145 | * Exit a parse tree produced by the {@code opBin} 146 | * labeled alternative in {@link EnquantoParser#expressao}. 147 | * @param ctx the parse tree 148 | */ 149 | void exitOpBin(EnquantoParser.OpBinContext ctx); 150 | /** 151 | * Enter a parse tree produced by the {@code id} 152 | * labeled alternative in {@link EnquantoParser#expressao}. 153 | * @param ctx the parse tree 154 | */ 155 | void enterId(EnquantoParser.IdContext ctx); 156 | /** 157 | * Exit a parse tree produced by the {@code id} 158 | * labeled alternative in {@link EnquantoParser#expressao}. 159 | * @param ctx the parse tree 160 | */ 161 | void exitId(EnquantoParser.IdContext ctx); 162 | /** 163 | * Enter a parse tree produced by the {@code expPar} 164 | * labeled alternative in {@link EnquantoParser#expressao}. 165 | * @param ctx the parse tree 166 | */ 167 | void enterExpPar(EnquantoParser.ExpParContext ctx); 168 | /** 169 | * Exit a parse tree produced by the {@code expPar} 170 | * labeled alternative in {@link EnquantoParser#expressao}. 171 | * @param ctx the parse tree 172 | */ 173 | void exitExpPar(EnquantoParser.ExpParContext ctx); 174 | /** 175 | * Enter a parse tree produced by the {@code bool} 176 | * labeled alternative in {@link EnquantoParser#booleano}. 177 | * @param ctx the parse tree 178 | */ 179 | void enterBool(EnquantoParser.BoolContext ctx); 180 | /** 181 | * Exit a parse tree produced by the {@code bool} 182 | * labeled alternative in {@link EnquantoParser#booleano}. 183 | * @param ctx the parse tree 184 | */ 185 | void exitBool(EnquantoParser.BoolContext ctx); 186 | /** 187 | * Enter a parse tree produced by the {@code eLogico} 188 | * labeled alternative in {@link EnquantoParser#booleano}. 189 | * @param ctx the parse tree 190 | */ 191 | void enterELogico(EnquantoParser.ELogicoContext ctx); 192 | /** 193 | * Exit a parse tree produced by the {@code eLogico} 194 | * labeled alternative in {@link EnquantoParser#booleano}. 195 | * @param ctx the parse tree 196 | */ 197 | void exitELogico(EnquantoParser.ELogicoContext ctx); 198 | /** 199 | * Enter a parse tree produced by the {@code naoLogico} 200 | * labeled alternative in {@link EnquantoParser#booleano}. 201 | * @param ctx the parse tree 202 | */ 203 | void enterNaoLogico(EnquantoParser.NaoLogicoContext ctx); 204 | /** 205 | * Exit a parse tree produced by the {@code naoLogico} 206 | * labeled alternative in {@link EnquantoParser#booleano}. 207 | * @param ctx the parse tree 208 | */ 209 | void exitNaoLogico(EnquantoParser.NaoLogicoContext ctx); 210 | /** 211 | * Enter a parse tree produced by the {@code opRel} 212 | * labeled alternative in {@link EnquantoParser#booleano}. 213 | * @param ctx the parse tree 214 | */ 215 | void enterOpRel(EnquantoParser.OpRelContext ctx); 216 | /** 217 | * Exit a parse tree produced by the {@code opRel} 218 | * labeled alternative in {@link EnquantoParser#booleano}. 219 | * @param ctx the parse tree 220 | */ 221 | void exitOpRel(EnquantoParser.OpRelContext ctx); 222 | /** 223 | * Enter a parse tree produced by the {@code boolPar} 224 | * labeled alternative in {@link EnquantoParser#booleano}. 225 | * @param ctx the parse tree 226 | */ 227 | void enterBoolPar(EnquantoParser.BoolParContext ctx); 228 | /** 229 | * Exit a parse tree produced by the {@code boolPar} 230 | * labeled alternative in {@link EnquantoParser#booleano}. 231 | * @param ctx the parse tree 232 | */ 233 | void exitBoolPar(EnquantoParser.BoolParContext ctx); 234 | } -------------------------------------------------------------------------------- /src/plp/enquanto/parser/EnquantoParser.java: -------------------------------------------------------------------------------- 1 | // Generated from ./src/plp/enquanto/parser/Enquanto.g4 by ANTLR 4.13.1 2 | package plp.enquanto.parser; 3 | import org.antlr.v4.runtime.atn.*; 4 | import org.antlr.v4.runtime.dfa.DFA; 5 | import org.antlr.v4.runtime.*; 6 | import org.antlr.v4.runtime.misc.*; 7 | import org.antlr.v4.runtime.tree.*; 8 | import java.util.List; 9 | import java.util.Iterator; 10 | import java.util.ArrayList; 11 | 12 | @SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue"}) 13 | public class EnquantoParser extends Parser { 14 | static { RuntimeMetaData.checkVersion("4.13.1", RuntimeMetaData.VERSION); } 15 | 16 | protected static final DFA[] _decisionToDFA; 17 | protected static final PredictionContextCache _sharedContextCache = 18 | new PredictionContextCache(); 19 | public static final int 20 | T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, T__5=6, T__6=7, T__7=8, T__8=9, 21 | T__9=10, T__10=11, T__11=12, T__12=13, T__13=14, T__14=15, T__15=16, T__16=17, 22 | T__17=18, T__18=19, T__19=20, T__20=21, T__21=22, BOOLEANO=23, INT=24, 23 | ID=25, TEXTO=26, Comentario=27, Espaco=28; 24 | public static final int 25 | RULE_programa = 0, RULE_seqComando = 1, RULE_comando = 2, RULE_expressao = 3, 26 | RULE_booleano = 4; 27 | private static String[] makeRuleNames() { 28 | return new String[] { 29 | "programa", "seqComando", "comando", "expressao", "booleano" 30 | }; 31 | } 32 | public static final String[] ruleNames = makeRuleNames(); 33 | 34 | private static String[] makeLiteralNames() { 35 | return new String[] { 36 | null, "';'", "':='", "'skip'", "'se'", "'entao'", "'senao'", "'enquanto'", 37 | "'faca'", "'exiba'", "'escreva'", "'{'", "'}'", "'leia'", "'*'", "'+'", 38 | "'-'", "'('", "')'", "'='", "'<='", "'nao'", "'e'" 39 | }; 40 | } 41 | private static final String[] _LITERAL_NAMES = makeLiteralNames(); 42 | private static String[] makeSymbolicNames() { 43 | return new String[] { 44 | null, null, null, null, null, null, null, null, null, null, null, null, 45 | null, null, null, null, null, null, null, null, null, null, null, "BOOLEANO", 46 | "INT", "ID", "TEXTO", "Comentario", "Espaco" 47 | }; 48 | } 49 | private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames(); 50 | public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES); 51 | 52 | /** 53 | * @deprecated Use {@link #VOCABULARY} instead. 54 | */ 55 | @Deprecated 56 | public static final String[] tokenNames; 57 | static { 58 | tokenNames = new String[_SYMBOLIC_NAMES.length]; 59 | for (int i = 0; i < tokenNames.length; i++) { 60 | tokenNames[i] = VOCABULARY.getLiteralName(i); 61 | if (tokenNames[i] == null) { 62 | tokenNames[i] = VOCABULARY.getSymbolicName(i); 63 | } 64 | 65 | if (tokenNames[i] == null) { 66 | tokenNames[i] = ""; 67 | } 68 | } 69 | } 70 | 71 | @Override 72 | @Deprecated 73 | public String[] getTokenNames() { 74 | return tokenNames; 75 | } 76 | 77 | @Override 78 | 79 | public Vocabulary getVocabulary() { 80 | return VOCABULARY; 81 | } 82 | 83 | @Override 84 | public String getGrammarFileName() { return "Enquanto.g4"; } 85 | 86 | @Override 87 | public String[] getRuleNames() { return ruleNames; } 88 | 89 | @Override 90 | public String getSerializedATN() { return _serializedATN; } 91 | 92 | @Override 93 | public ATN getATN() { return _ATN; } 94 | 95 | public EnquantoParser(TokenStream input) { 96 | super(input); 97 | _interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache); 98 | } 99 | 100 | @SuppressWarnings("CheckReturnValue") 101 | public static class ProgramaContext extends ParserRuleContext { 102 | public SeqComandoContext seqComando() { 103 | return getRuleContext(SeqComandoContext.class,0); 104 | } 105 | public ProgramaContext(ParserRuleContext parent, int invokingState) { 106 | super(parent, invokingState); 107 | } 108 | @Override public int getRuleIndex() { return RULE_programa; } 109 | @Override 110 | public void enterRule(ParseTreeListener listener) { 111 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).enterPrograma(this); 112 | } 113 | @Override 114 | public void exitRule(ParseTreeListener listener) { 115 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).exitPrograma(this); 116 | } 117 | } 118 | 119 | public final ProgramaContext programa() throws RecognitionException { 120 | ProgramaContext _localctx = new ProgramaContext(_ctx, getState()); 121 | enterRule(_localctx, 0, RULE_programa); 122 | try { 123 | enterOuterAlt(_localctx, 1); 124 | { 125 | setState(10); 126 | seqComando(); 127 | } 128 | } 129 | catch (RecognitionException re) { 130 | _localctx.exception = re; 131 | _errHandler.reportError(this, re); 132 | _errHandler.recover(this, re); 133 | } 134 | finally { 135 | exitRule(); 136 | } 137 | return _localctx; 138 | } 139 | 140 | @SuppressWarnings("CheckReturnValue") 141 | public static class SeqComandoContext extends ParserRuleContext { 142 | public List comando() { 143 | return getRuleContexts(ComandoContext.class); 144 | } 145 | public ComandoContext comando(int i) { 146 | return getRuleContext(ComandoContext.class,i); 147 | } 148 | public SeqComandoContext(ParserRuleContext parent, int invokingState) { 149 | super(parent, invokingState); 150 | } 151 | @Override public int getRuleIndex() { return RULE_seqComando; } 152 | @Override 153 | public void enterRule(ParseTreeListener listener) { 154 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).enterSeqComando(this); 155 | } 156 | @Override 157 | public void exitRule(ParseTreeListener listener) { 158 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).exitSeqComando(this); 159 | } 160 | } 161 | 162 | public final SeqComandoContext seqComando() throws RecognitionException { 163 | SeqComandoContext _localctx = new SeqComandoContext(_ctx, getState()); 164 | enterRule(_localctx, 2, RULE_seqComando); 165 | int _la; 166 | try { 167 | enterOuterAlt(_localctx, 1); 168 | { 169 | setState(12); 170 | comando(); 171 | setState(17); 172 | _errHandler.sync(this); 173 | _la = _input.LA(1); 174 | while (_la==T__0) { 175 | { 176 | { 177 | setState(13); 178 | match(T__0); 179 | setState(14); 180 | comando(); 181 | } 182 | } 183 | setState(19); 184 | _errHandler.sync(this); 185 | _la = _input.LA(1); 186 | } 187 | } 188 | } 189 | catch (RecognitionException re) { 190 | _localctx.exception = re; 191 | _errHandler.reportError(this, re); 192 | _errHandler.recover(this, re); 193 | } 194 | finally { 195 | exitRule(); 196 | } 197 | return _localctx; 198 | } 199 | 200 | @SuppressWarnings("CheckReturnValue") 201 | public static class ComandoContext extends ParserRuleContext { 202 | public ComandoContext(ParserRuleContext parent, int invokingState) { 203 | super(parent, invokingState); 204 | } 205 | @Override public int getRuleIndex() { return RULE_comando; } 206 | 207 | public ComandoContext() { } 208 | public void copyFrom(ComandoContext ctx) { 209 | super.copyFrom(ctx); 210 | } 211 | } 212 | @SuppressWarnings("CheckReturnValue") 213 | public static class AtribuicaoContext extends ComandoContext { 214 | public TerminalNode ID() { return getToken(EnquantoParser.ID, 0); } 215 | public ExpressaoContext expressao() { 216 | return getRuleContext(ExpressaoContext.class,0); 217 | } 218 | public AtribuicaoContext(ComandoContext ctx) { copyFrom(ctx); } 219 | @Override 220 | public void enterRule(ParseTreeListener listener) { 221 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).enterAtribuicao(this); 222 | } 223 | @Override 224 | public void exitRule(ParseTreeListener listener) { 225 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).exitAtribuicao(this); 226 | } 227 | } 228 | @SuppressWarnings("CheckReturnValue") 229 | public static class SeContext extends ComandoContext { 230 | public BooleanoContext booleano() { 231 | return getRuleContext(BooleanoContext.class,0); 232 | } 233 | public List comando() { 234 | return getRuleContexts(ComandoContext.class); 235 | } 236 | public ComandoContext comando(int i) { 237 | return getRuleContext(ComandoContext.class,i); 238 | } 239 | public SeContext(ComandoContext ctx) { copyFrom(ctx); } 240 | @Override 241 | public void enterRule(ParseTreeListener listener) { 242 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).enterSe(this); 243 | } 244 | @Override 245 | public void exitRule(ParseTreeListener listener) { 246 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).exitSe(this); 247 | } 248 | } 249 | @SuppressWarnings("CheckReturnValue") 250 | public static class ExibaContext extends ComandoContext { 251 | public TerminalNode TEXTO() { return getToken(EnquantoParser.TEXTO, 0); } 252 | public ExibaContext(ComandoContext ctx) { copyFrom(ctx); } 253 | @Override 254 | public void enterRule(ParseTreeListener listener) { 255 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).enterExiba(this); 256 | } 257 | @Override 258 | public void exitRule(ParseTreeListener listener) { 259 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).exitExiba(this); 260 | } 261 | } 262 | @SuppressWarnings("CheckReturnValue") 263 | public static class EnquantoContext extends ComandoContext { 264 | public BooleanoContext booleano() { 265 | return getRuleContext(BooleanoContext.class,0); 266 | } 267 | public ComandoContext comando() { 268 | return getRuleContext(ComandoContext.class,0); 269 | } 270 | public EnquantoContext(ComandoContext ctx) { copyFrom(ctx); } 271 | @Override 272 | public void enterRule(ParseTreeListener listener) { 273 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).enterEnquanto(this); 274 | } 275 | @Override 276 | public void exitRule(ParseTreeListener listener) { 277 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).exitEnquanto(this); 278 | } 279 | } 280 | @SuppressWarnings("CheckReturnValue") 281 | public static class BlocoContext extends ComandoContext { 282 | public SeqComandoContext seqComando() { 283 | return getRuleContext(SeqComandoContext.class,0); 284 | } 285 | public BlocoContext(ComandoContext ctx) { copyFrom(ctx); } 286 | @Override 287 | public void enterRule(ParseTreeListener listener) { 288 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).enterBloco(this); 289 | } 290 | @Override 291 | public void exitRule(ParseTreeListener listener) { 292 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).exitBloco(this); 293 | } 294 | } 295 | @SuppressWarnings("CheckReturnValue") 296 | public static class EscrevaContext extends ComandoContext { 297 | public ExpressaoContext expressao() { 298 | return getRuleContext(ExpressaoContext.class,0); 299 | } 300 | public EscrevaContext(ComandoContext ctx) { copyFrom(ctx); } 301 | @Override 302 | public void enterRule(ParseTreeListener listener) { 303 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).enterEscreva(this); 304 | } 305 | @Override 306 | public void exitRule(ParseTreeListener listener) { 307 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).exitEscreva(this); 308 | } 309 | } 310 | @SuppressWarnings("CheckReturnValue") 311 | public static class SkipContext extends ComandoContext { 312 | public SkipContext(ComandoContext ctx) { copyFrom(ctx); } 313 | @Override 314 | public void enterRule(ParseTreeListener listener) { 315 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).enterSkip(this); 316 | } 317 | @Override 318 | public void exitRule(ParseTreeListener listener) { 319 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).exitSkip(this); 320 | } 321 | } 322 | 323 | public final ComandoContext comando() throws RecognitionException { 324 | ComandoContext _localctx = new ComandoContext(_ctx, getState()); 325 | enterRule(_localctx, 4, RULE_comando); 326 | try { 327 | setState(44); 328 | _errHandler.sync(this); 329 | switch (_input.LA(1)) { 330 | case ID: 331 | _localctx = new AtribuicaoContext(_localctx); 332 | enterOuterAlt(_localctx, 1); 333 | { 334 | setState(20); 335 | match(ID); 336 | setState(21); 337 | match(T__1); 338 | setState(22); 339 | expressao(0); 340 | } 341 | break; 342 | case T__2: 343 | _localctx = new SkipContext(_localctx); 344 | enterOuterAlt(_localctx, 2); 345 | { 346 | setState(23); 347 | match(T__2); 348 | } 349 | break; 350 | case T__3: 351 | _localctx = new SeContext(_localctx); 352 | enterOuterAlt(_localctx, 3); 353 | { 354 | setState(24); 355 | match(T__3); 356 | setState(25); 357 | booleano(0); 358 | setState(26); 359 | match(T__4); 360 | setState(27); 361 | comando(); 362 | setState(28); 363 | match(T__5); 364 | setState(29); 365 | comando(); 366 | } 367 | break; 368 | case T__6: 369 | _localctx = new EnquantoContext(_localctx); 370 | enterOuterAlt(_localctx, 4); 371 | { 372 | setState(31); 373 | match(T__6); 374 | setState(32); 375 | booleano(0); 376 | setState(33); 377 | match(T__7); 378 | setState(34); 379 | comando(); 380 | } 381 | break; 382 | case T__8: 383 | _localctx = new ExibaContext(_localctx); 384 | enterOuterAlt(_localctx, 5); 385 | { 386 | setState(36); 387 | match(T__8); 388 | setState(37); 389 | match(TEXTO); 390 | } 391 | break; 392 | case T__9: 393 | _localctx = new EscrevaContext(_localctx); 394 | enterOuterAlt(_localctx, 6); 395 | { 396 | setState(38); 397 | match(T__9); 398 | setState(39); 399 | expressao(0); 400 | } 401 | break; 402 | case T__10: 403 | _localctx = new BlocoContext(_localctx); 404 | enterOuterAlt(_localctx, 7); 405 | { 406 | setState(40); 407 | match(T__10); 408 | setState(41); 409 | seqComando(); 410 | setState(42); 411 | match(T__11); 412 | } 413 | break; 414 | default: 415 | throw new NoViableAltException(this); 416 | } 417 | } 418 | catch (RecognitionException re) { 419 | _localctx.exception = re; 420 | _errHandler.reportError(this, re); 421 | _errHandler.recover(this, re); 422 | } 423 | finally { 424 | exitRule(); 425 | } 426 | return _localctx; 427 | } 428 | 429 | @SuppressWarnings("CheckReturnValue") 430 | public static class ExpressaoContext extends ParserRuleContext { 431 | public ExpressaoContext(ParserRuleContext parent, int invokingState) { 432 | super(parent, invokingState); 433 | } 434 | @Override public int getRuleIndex() { return RULE_expressao; } 435 | 436 | public ExpressaoContext() { } 437 | public void copyFrom(ExpressaoContext ctx) { 438 | super.copyFrom(ctx); 439 | } 440 | } 441 | @SuppressWarnings("CheckReturnValue") 442 | public static class LeiaContext extends ExpressaoContext { 443 | public LeiaContext(ExpressaoContext ctx) { copyFrom(ctx); } 444 | @Override 445 | public void enterRule(ParseTreeListener listener) { 446 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).enterLeia(this); 447 | } 448 | @Override 449 | public void exitRule(ParseTreeListener listener) { 450 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).exitLeia(this); 451 | } 452 | } 453 | @SuppressWarnings("CheckReturnValue") 454 | public static class InteiroContext extends ExpressaoContext { 455 | public TerminalNode INT() { return getToken(EnquantoParser.INT, 0); } 456 | public InteiroContext(ExpressaoContext ctx) { copyFrom(ctx); } 457 | @Override 458 | public void enterRule(ParseTreeListener listener) { 459 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).enterInteiro(this); 460 | } 461 | @Override 462 | public void exitRule(ParseTreeListener listener) { 463 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).exitInteiro(this); 464 | } 465 | } 466 | @SuppressWarnings("CheckReturnValue") 467 | public static class OpBinContext extends ExpressaoContext { 468 | public List expressao() { 469 | return getRuleContexts(ExpressaoContext.class); 470 | } 471 | public ExpressaoContext expressao(int i) { 472 | return getRuleContext(ExpressaoContext.class,i); 473 | } 474 | public OpBinContext(ExpressaoContext ctx) { copyFrom(ctx); } 475 | @Override 476 | public void enterRule(ParseTreeListener listener) { 477 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).enterOpBin(this); 478 | } 479 | @Override 480 | public void exitRule(ParseTreeListener listener) { 481 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).exitOpBin(this); 482 | } 483 | } 484 | @SuppressWarnings("CheckReturnValue") 485 | public static class IdContext extends ExpressaoContext { 486 | public TerminalNode ID() { return getToken(EnquantoParser.ID, 0); } 487 | public IdContext(ExpressaoContext ctx) { copyFrom(ctx); } 488 | @Override 489 | public void enterRule(ParseTreeListener listener) { 490 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).enterId(this); 491 | } 492 | @Override 493 | public void exitRule(ParseTreeListener listener) { 494 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).exitId(this); 495 | } 496 | } 497 | @SuppressWarnings("CheckReturnValue") 498 | public static class ExpParContext extends ExpressaoContext { 499 | public ExpressaoContext expressao() { 500 | return getRuleContext(ExpressaoContext.class,0); 501 | } 502 | public ExpParContext(ExpressaoContext ctx) { copyFrom(ctx); } 503 | @Override 504 | public void enterRule(ParseTreeListener listener) { 505 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).enterExpPar(this); 506 | } 507 | @Override 508 | public void exitRule(ParseTreeListener listener) { 509 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).exitExpPar(this); 510 | } 511 | } 512 | 513 | public final ExpressaoContext expressao() throws RecognitionException { 514 | return expressao(0); 515 | } 516 | 517 | private ExpressaoContext expressao(int _p) throws RecognitionException { 518 | ParserRuleContext _parentctx = _ctx; 519 | int _parentState = getState(); 520 | ExpressaoContext _localctx = new ExpressaoContext(_ctx, _parentState); 521 | ExpressaoContext _prevctx = _localctx; 522 | int _startState = 6; 523 | enterRecursionRule(_localctx, 6, RULE_expressao, _p); 524 | int _la; 525 | try { 526 | int _alt; 527 | enterOuterAlt(_localctx, 1); 528 | { 529 | setState(54); 530 | _errHandler.sync(this); 531 | switch (_input.LA(1)) { 532 | case INT: 533 | { 534 | _localctx = new InteiroContext(_localctx); 535 | _ctx = _localctx; 536 | _prevctx = _localctx; 537 | 538 | setState(47); 539 | match(INT); 540 | } 541 | break; 542 | case T__12: 543 | { 544 | _localctx = new LeiaContext(_localctx); 545 | _ctx = _localctx; 546 | _prevctx = _localctx; 547 | setState(48); 548 | match(T__12); 549 | } 550 | break; 551 | case ID: 552 | { 553 | _localctx = new IdContext(_localctx); 554 | _ctx = _localctx; 555 | _prevctx = _localctx; 556 | setState(49); 557 | match(ID); 558 | } 559 | break; 560 | case T__16: 561 | { 562 | _localctx = new ExpParContext(_localctx); 563 | _ctx = _localctx; 564 | _prevctx = _localctx; 565 | setState(50); 566 | match(T__16); 567 | setState(51); 568 | expressao(0); 569 | setState(52); 570 | match(T__17); 571 | } 572 | break; 573 | default: 574 | throw new NoViableAltException(this); 575 | } 576 | _ctx.stop = _input.LT(-1); 577 | setState(64); 578 | _errHandler.sync(this); 579 | _alt = getInterpreter().adaptivePredict(_input,4,_ctx); 580 | while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) { 581 | if ( _alt==1 ) { 582 | if ( _parseListeners!=null ) triggerExitRuleEvent(); 583 | _prevctx = _localctx; 584 | { 585 | setState(62); 586 | _errHandler.sync(this); 587 | switch ( getInterpreter().adaptivePredict(_input,3,_ctx) ) { 588 | case 1: 589 | { 590 | _localctx = new OpBinContext(new ExpressaoContext(_parentctx, _parentState)); 591 | pushNewRecursionContext(_localctx, _startState, RULE_expressao); 592 | setState(56); 593 | if (!(precpred(_ctx, 3))) throw new FailedPredicateException(this, "precpred(_ctx, 3)"); 594 | setState(57); 595 | match(T__13); 596 | setState(58); 597 | expressao(4); 598 | } 599 | break; 600 | case 2: 601 | { 602 | _localctx = new OpBinContext(new ExpressaoContext(_parentctx, _parentState)); 603 | pushNewRecursionContext(_localctx, _startState, RULE_expressao); 604 | setState(59); 605 | if (!(precpred(_ctx, 2))) throw new FailedPredicateException(this, "precpred(_ctx, 2)"); 606 | setState(60); 607 | _la = _input.LA(1); 608 | if ( !(_la==T__14 || _la==T__15) ) { 609 | _errHandler.recoverInline(this); 610 | } 611 | else { 612 | if ( _input.LA(1)==Token.EOF ) matchedEOF = true; 613 | _errHandler.reportMatch(this); 614 | consume(); 615 | } 616 | setState(61); 617 | expressao(3); 618 | } 619 | break; 620 | } 621 | } 622 | } 623 | setState(66); 624 | _errHandler.sync(this); 625 | _alt = getInterpreter().adaptivePredict(_input,4,_ctx); 626 | } 627 | } 628 | } 629 | catch (RecognitionException re) { 630 | _localctx.exception = re; 631 | _errHandler.reportError(this, re); 632 | _errHandler.recover(this, re); 633 | } 634 | finally { 635 | unrollRecursionContexts(_parentctx); 636 | } 637 | return _localctx; 638 | } 639 | 640 | @SuppressWarnings("CheckReturnValue") 641 | public static class BooleanoContext extends ParserRuleContext { 642 | public BooleanoContext(ParserRuleContext parent, int invokingState) { 643 | super(parent, invokingState); 644 | } 645 | @Override public int getRuleIndex() { return RULE_booleano; } 646 | 647 | public BooleanoContext() { } 648 | public void copyFrom(BooleanoContext ctx) { 649 | super.copyFrom(ctx); 650 | } 651 | } 652 | @SuppressWarnings("CheckReturnValue") 653 | public static class BoolContext extends BooleanoContext { 654 | public TerminalNode BOOLEANO() { return getToken(EnquantoParser.BOOLEANO, 0); } 655 | public BoolContext(BooleanoContext ctx) { copyFrom(ctx); } 656 | @Override 657 | public void enterRule(ParseTreeListener listener) { 658 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).enterBool(this); 659 | } 660 | @Override 661 | public void exitRule(ParseTreeListener listener) { 662 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).exitBool(this); 663 | } 664 | } 665 | @SuppressWarnings("CheckReturnValue") 666 | public static class ELogicoContext extends BooleanoContext { 667 | public List booleano() { 668 | return getRuleContexts(BooleanoContext.class); 669 | } 670 | public BooleanoContext booleano(int i) { 671 | return getRuleContext(BooleanoContext.class,i); 672 | } 673 | public ELogicoContext(BooleanoContext ctx) { copyFrom(ctx); } 674 | @Override 675 | public void enterRule(ParseTreeListener listener) { 676 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).enterELogico(this); 677 | } 678 | @Override 679 | public void exitRule(ParseTreeListener listener) { 680 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).exitELogico(this); 681 | } 682 | } 683 | @SuppressWarnings("CheckReturnValue") 684 | public static class NaoLogicoContext extends BooleanoContext { 685 | public BooleanoContext booleano() { 686 | return getRuleContext(BooleanoContext.class,0); 687 | } 688 | public NaoLogicoContext(BooleanoContext ctx) { copyFrom(ctx); } 689 | @Override 690 | public void enterRule(ParseTreeListener listener) { 691 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).enterNaoLogico(this); 692 | } 693 | @Override 694 | public void exitRule(ParseTreeListener listener) { 695 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).exitNaoLogico(this); 696 | } 697 | } 698 | @SuppressWarnings("CheckReturnValue") 699 | public static class OpRelContext extends BooleanoContext { 700 | public List expressao() { 701 | return getRuleContexts(ExpressaoContext.class); 702 | } 703 | public ExpressaoContext expressao(int i) { 704 | return getRuleContext(ExpressaoContext.class,i); 705 | } 706 | public OpRelContext(BooleanoContext ctx) { copyFrom(ctx); } 707 | @Override 708 | public void enterRule(ParseTreeListener listener) { 709 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).enterOpRel(this); 710 | } 711 | @Override 712 | public void exitRule(ParseTreeListener listener) { 713 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).exitOpRel(this); 714 | } 715 | } 716 | @SuppressWarnings("CheckReturnValue") 717 | public static class BoolParContext extends BooleanoContext { 718 | public BooleanoContext booleano() { 719 | return getRuleContext(BooleanoContext.class,0); 720 | } 721 | public BoolParContext(BooleanoContext ctx) { copyFrom(ctx); } 722 | @Override 723 | public void enterRule(ParseTreeListener listener) { 724 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).enterBoolPar(this); 725 | } 726 | @Override 727 | public void exitRule(ParseTreeListener listener) { 728 | if ( listener instanceof EnquantoListener ) ((EnquantoListener)listener).exitBoolPar(this); 729 | } 730 | } 731 | 732 | public final BooleanoContext booleano() throws RecognitionException { 733 | return booleano(0); 734 | } 735 | 736 | private BooleanoContext booleano(int _p) throws RecognitionException { 737 | ParserRuleContext _parentctx = _ctx; 738 | int _parentState = getState(); 739 | BooleanoContext _localctx = new BooleanoContext(_ctx, _parentState); 740 | BooleanoContext _prevctx = _localctx; 741 | int _startState = 8; 742 | enterRecursionRule(_localctx, 8, RULE_booleano, _p); 743 | try { 744 | int _alt; 745 | enterOuterAlt(_localctx, 1); 746 | { 747 | setState(83); 748 | _errHandler.sync(this); 749 | switch ( getInterpreter().adaptivePredict(_input,5,_ctx) ) { 750 | case 1: 751 | { 752 | _localctx = new BoolContext(_localctx); 753 | _ctx = _localctx; 754 | _prevctx = _localctx; 755 | 756 | setState(68); 757 | match(BOOLEANO); 758 | } 759 | break; 760 | case 2: 761 | { 762 | _localctx = new OpRelContext(_localctx); 763 | _ctx = _localctx; 764 | _prevctx = _localctx; 765 | setState(69); 766 | expressao(0); 767 | setState(70); 768 | match(T__18); 769 | setState(71); 770 | expressao(0); 771 | } 772 | break; 773 | case 3: 774 | { 775 | _localctx = new OpRelContext(_localctx); 776 | _ctx = _localctx; 777 | _prevctx = _localctx; 778 | setState(73); 779 | expressao(0); 780 | setState(74); 781 | match(T__19); 782 | setState(75); 783 | expressao(0); 784 | } 785 | break; 786 | case 4: 787 | { 788 | _localctx = new NaoLogicoContext(_localctx); 789 | _ctx = _localctx; 790 | _prevctx = _localctx; 791 | setState(77); 792 | match(T__20); 793 | setState(78); 794 | booleano(3); 795 | } 796 | break; 797 | case 5: 798 | { 799 | _localctx = new BoolParContext(_localctx); 800 | _ctx = _localctx; 801 | _prevctx = _localctx; 802 | setState(79); 803 | match(T__16); 804 | setState(80); 805 | booleano(0); 806 | setState(81); 807 | match(T__17); 808 | } 809 | break; 810 | } 811 | _ctx.stop = _input.LT(-1); 812 | setState(90); 813 | _errHandler.sync(this); 814 | _alt = getInterpreter().adaptivePredict(_input,6,_ctx); 815 | while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) { 816 | if ( _alt==1 ) { 817 | if ( _parseListeners!=null ) triggerExitRuleEvent(); 818 | _prevctx = _localctx; 819 | { 820 | { 821 | _localctx = new ELogicoContext(new BooleanoContext(_parentctx, _parentState)); 822 | pushNewRecursionContext(_localctx, _startState, RULE_booleano); 823 | setState(85); 824 | if (!(precpred(_ctx, 2))) throw new FailedPredicateException(this, "precpred(_ctx, 2)"); 825 | setState(86); 826 | match(T__21); 827 | setState(87); 828 | booleano(3); 829 | } 830 | } 831 | } 832 | setState(92); 833 | _errHandler.sync(this); 834 | _alt = getInterpreter().adaptivePredict(_input,6,_ctx); 835 | } 836 | } 837 | } 838 | catch (RecognitionException re) { 839 | _localctx.exception = re; 840 | _errHandler.reportError(this, re); 841 | _errHandler.recover(this, re); 842 | } 843 | finally { 844 | unrollRecursionContexts(_parentctx); 845 | } 846 | return _localctx; 847 | } 848 | 849 | public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) { 850 | switch (ruleIndex) { 851 | case 3: 852 | return expressao_sempred((ExpressaoContext)_localctx, predIndex); 853 | case 4: 854 | return booleano_sempred((BooleanoContext)_localctx, predIndex); 855 | } 856 | return true; 857 | } 858 | private boolean expressao_sempred(ExpressaoContext _localctx, int predIndex) { 859 | switch (predIndex) { 860 | case 0: 861 | return precpred(_ctx, 3); 862 | case 1: 863 | return precpred(_ctx, 2); 864 | } 865 | return true; 866 | } 867 | private boolean booleano_sempred(BooleanoContext _localctx, int predIndex) { 868 | switch (predIndex) { 869 | case 2: 870 | return precpred(_ctx, 2); 871 | } 872 | return true; 873 | } 874 | 875 | public static final String _serializedATN = 876 | "\u0004\u0001\u001c^\u0002\u0000\u0007\u0000\u0002\u0001\u0007\u0001\u0002"+ 877 | "\u0002\u0007\u0002\u0002\u0003\u0007\u0003\u0002\u0004\u0007\u0004\u0001"+ 878 | "\u0000\u0001\u0000\u0001\u0001\u0001\u0001\u0001\u0001\u0005\u0001\u0010"+ 879 | "\b\u0001\n\u0001\f\u0001\u0013\t\u0001\u0001\u0002\u0001\u0002\u0001\u0002"+ 880 | "\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002"+ 881 | "\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002"+ 882 | "\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002"+ 883 | "\u0001\u0002\u0001\u0002\u0001\u0002\u0003\u0002-\b\u0002\u0001\u0003"+ 884 | "\u0001\u0003\u0001\u0003\u0001\u0003\u0001\u0003\u0001\u0003\u0001\u0003"+ 885 | "\u0001\u0003\u0003\u00037\b\u0003\u0001\u0003\u0001\u0003\u0001\u0003"+ 886 | "\u0001\u0003\u0001\u0003\u0001\u0003\u0005\u0003?\b\u0003\n\u0003\f\u0003"+ 887 | "B\t\u0003\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004"+ 888 | "\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004"+ 889 | "\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0003\u0004"+ 890 | "T\b\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0005\u0004Y\b\u0004\n\u0004"+ 891 | "\f\u0004\\\t\u0004\u0001\u0004\u0000\u0002\u0006\b\u0005\u0000\u0002\u0004"+ 892 | "\u0006\b\u0000\u0001\u0001\u0000\u000f\u0010i\u0000\n\u0001\u0000\u0000"+ 893 | "\u0000\u0002\f\u0001\u0000\u0000\u0000\u0004,\u0001\u0000\u0000\u0000"+ 894 | "\u00066\u0001\u0000\u0000\u0000\bS\u0001\u0000\u0000\u0000\n\u000b\u0003"+ 895 | "\u0002\u0001\u0000\u000b\u0001\u0001\u0000\u0000\u0000\f\u0011\u0003\u0004"+ 896 | "\u0002\u0000\r\u000e\u0005\u0001\u0000\u0000\u000e\u0010\u0003\u0004\u0002"+ 897 | "\u0000\u000f\r\u0001\u0000\u0000\u0000\u0010\u0013\u0001\u0000\u0000\u0000"+ 898 | "\u0011\u000f\u0001\u0000\u0000\u0000\u0011\u0012\u0001\u0000\u0000\u0000"+ 899 | "\u0012\u0003\u0001\u0000\u0000\u0000\u0013\u0011\u0001\u0000\u0000\u0000"+ 900 | "\u0014\u0015\u0005\u0019\u0000\u0000\u0015\u0016\u0005\u0002\u0000\u0000"+ 901 | "\u0016-\u0003\u0006\u0003\u0000\u0017-\u0005\u0003\u0000\u0000\u0018\u0019"+ 902 | "\u0005\u0004\u0000\u0000\u0019\u001a\u0003\b\u0004\u0000\u001a\u001b\u0005"+ 903 | "\u0005\u0000\u0000\u001b\u001c\u0003\u0004\u0002\u0000\u001c\u001d\u0005"+ 904 | "\u0006\u0000\u0000\u001d\u001e\u0003\u0004\u0002\u0000\u001e-\u0001\u0000"+ 905 | "\u0000\u0000\u001f \u0005\u0007\u0000\u0000 !\u0003\b\u0004\u0000!\"\u0005"+ 906 | "\b\u0000\u0000\"#\u0003\u0004\u0002\u0000#-\u0001\u0000\u0000\u0000$%"+ 907 | "\u0005\t\u0000\u0000%-\u0005\u001a\u0000\u0000&\'\u0005\n\u0000\u0000"+ 908 | "\'-\u0003\u0006\u0003\u0000()\u0005\u000b\u0000\u0000)*\u0003\u0002\u0001"+ 909 | "\u0000*+\u0005\f\u0000\u0000+-\u0001\u0000\u0000\u0000,\u0014\u0001\u0000"+ 910 | "\u0000\u0000,\u0017\u0001\u0000\u0000\u0000,\u0018\u0001\u0000\u0000\u0000"+ 911 | ",\u001f\u0001\u0000\u0000\u0000,$\u0001\u0000\u0000\u0000,&\u0001\u0000"+ 912 | "\u0000\u0000,(\u0001\u0000\u0000\u0000-\u0005\u0001\u0000\u0000\u0000"+ 913 | "./\u0006\u0003\uffff\uffff\u0000/7\u0005\u0018\u0000\u000007\u0005\r\u0000"+ 914 | "\u000017\u0005\u0019\u0000\u000023\u0005\u0011\u0000\u000034\u0003\u0006"+ 915 | "\u0003\u000045\u0005\u0012\u0000\u000057\u0001\u0000\u0000\u00006.\u0001"+ 916 | "\u0000\u0000\u000060\u0001\u0000\u0000\u000061\u0001\u0000\u0000\u0000"+ 917 | "62\u0001\u0000\u0000\u00007@\u0001\u0000\u0000\u000089\n\u0003\u0000\u0000"+ 918 | "9:\u0005\u000e\u0000\u0000:?\u0003\u0006\u0003\u0004;<\n\u0002\u0000\u0000"+ 919 | "<=\u0007\u0000\u0000\u0000=?\u0003\u0006\u0003\u0003>8\u0001\u0000\u0000"+ 920 | "\u0000>;\u0001\u0000\u0000\u0000?B\u0001\u0000\u0000\u0000@>\u0001\u0000"+ 921 | "\u0000\u0000@A\u0001\u0000\u0000\u0000A\u0007\u0001\u0000\u0000\u0000"+ 922 | "B@\u0001\u0000\u0000\u0000CD\u0006\u0004\uffff\uffff\u0000DT\u0005\u0017"+ 923 | "\u0000\u0000EF\u0003\u0006\u0003\u0000FG\u0005\u0013\u0000\u0000GH\u0003"+ 924 | "\u0006\u0003\u0000HT\u0001\u0000\u0000\u0000IJ\u0003\u0006\u0003\u0000"+ 925 | "JK\u0005\u0014\u0000\u0000KL\u0003\u0006\u0003\u0000LT\u0001\u0000\u0000"+ 926 | "\u0000MN\u0005\u0015\u0000\u0000NT\u0003\b\u0004\u0003OP\u0005\u0011\u0000"+ 927 | "\u0000PQ\u0003\b\u0004\u0000QR\u0005\u0012\u0000\u0000RT\u0001\u0000\u0000"+ 928 | "\u0000SC\u0001\u0000\u0000\u0000SE\u0001\u0000\u0000\u0000SI\u0001\u0000"+ 929 | "\u0000\u0000SM\u0001\u0000\u0000\u0000SO\u0001\u0000\u0000\u0000TZ\u0001"+ 930 | "\u0000\u0000\u0000UV\n\u0002\u0000\u0000VW\u0005\u0016\u0000\u0000WY\u0003"+ 931 | "\b\u0004\u0003XU\u0001\u0000\u0000\u0000Y\\\u0001\u0000\u0000\u0000ZX"+ 932 | "\u0001\u0000\u0000\u0000Z[\u0001\u0000\u0000\u0000[\t\u0001\u0000\u0000"+ 933 | "\u0000\\Z\u0001\u0000\u0000\u0000\u0007\u0011,6>@SZ"; 934 | public static final ATN _ATN = 935 | new ATNDeserializer().deserialize(_serializedATN.toCharArray()); 936 | static { 937 | _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()]; 938 | for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) { 939 | _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); 940 | } 941 | } 942 | } -------------------------------------------------------------------------------- /teste.while: -------------------------------------------------------------------------------- 1 | a := 10; 2 | escreva a; 3 | exiba "as" -------------------------------------------------------------------------------- /testes/escolha1.while: -------------------------------------------------------------------------------- 1 | x = leia 2 | escolha x 3 | caso 1 : exiba "um" 4 | caso 2 : exiba "dois" 5 | outro : exiba "outro numero" 6 | -------------------------------------------------------------------------------- /testes/escolha2.while: -------------------------------------------------------------------------------- 1 | x = leia 2 | escolha x 3 | caso 1 : exiba "um" 4 | caso 2 : exiba "dois" 5 | caso 1 : exiba "one" 6 | outro : exiba "outro numero" 7 | -------------------------------------------------------------------------------- /testes/escolha3.while: -------------------------------------------------------------------------------- 1 | x = leia 2 | escolha x + 1 3 | caso 1 : exiba "um" 4 | caso 2 : exiba "dois" 5 | outro : exiba "outro numero" 6 | -------------------------------------------------------------------------------- /testes/funcao1.while: -------------------------------------------------------------------------------- 1 | soma(a,b) = a + b ; 2 | 3 | escreva soma(2,3) 4 | -------------------------------------------------------------------------------- /testes/funcao2.while: -------------------------------------------------------------------------------- 1 | soma(a,b) = a + b ; 2 | 3 | soma3(a,b,c) = soma(a, soma(b, c)); 4 | 5 | escreva soma3(2,3,4) 6 | -------------------------------------------------------------------------------- /testes/funcao3.while: -------------------------------------------------------------------------------- 1 | x = 10; 2 | 3 | soma(x, y) = x + y; 4 | 5 | escreva soma(17, x + 1) 6 | -------------------------------------------------------------------------------- /testes/funcao4.while: -------------------------------------------------------------------------------- 1 | x := 10; 2 | f(a, b) = a + b + g(a, b); 3 | g(x, y) = x * y; 4 | 5 | escreva f(2, 3) 6 | -------------------------------------------------------------------------------- /testes/para1.while: -------------------------------------------------------------------------------- 1 | n := 10; 2 | para i de 1 ate n faca { 3 | escreva i; 4 | } 5 | -------------------------------------------------------------------------------- /testes/para2.while: -------------------------------------------------------------------------------- 1 | n := 1; 2 | para i de 1 ate 100 passo n faca { 3 | escreva i; 4 | n := n + 1 5 | } 6 | -------------------------------------------------------------------------------- /testes/para3.while: -------------------------------------------------------------------------------- 1 | n := 100; 2 | para i de 1 ate n faca { 3 | escreva i; 4 | n := n / 2 5 | } 6 | -------------------------------------------------------------------------------- /testes/se1.while: -------------------------------------------------------------------------------- 1 | nota := leia; 2 | se nota>=6 entao 3 | exiba "Aprovado" 4 | senaose nota >= 2 entao 5 | exiba "Recuperacao" 6 | senao 7 | exiba "Reprovado" 8 | -------------------------------------------------------------------------------- /testes/se2.while: -------------------------------------------------------------------------------- 1 | n := leia; 2 | n = n - n / 5 * 5; 3 | se n=0 então exiba "zero" 4 | senaose n = 1 entao exiba "um" 5 | senaose n = 2 entao exiba "dois" 6 | senaose n = 3 entao exiba "tres" 7 | senao exiba "quatro 8 | -------------------------------------------------------------------------------- /testes/se3.while: -------------------------------------------------------------------------------- 1 | n := 10; 2 | se n < 20 então exiba "menor do que vinte" 3 | senaose n < 15 entao exiba "menor do que quinze" 4 | senao exiba "nao sei" 5 | -------------------------------------------------------------------------------- /while: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | java -Xmx1879m -jar while.jar $1 -------------------------------------------------------------------------------- /while.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | java -jar while.jar %1 -------------------------------------------------------------------------------- /while.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrlucena/while/92824b20e4f3125b26cff4c7cc180ceaab11080e/while.jar --------------------------------------------------------------------------------